Page 1 of 1

Passing Sprites to Functions

Posted: Tue Oct 27, 2015 9:25 pm
by matteus
Is there a way I can do this?

Code: Select all

u16 loadExperts(Sprite Expert1, Sprite Expert2) {
    SYS_disableInts();
    VDP_setPalette(PAL2, Expert1.palette->data);
    VDP_setPalette(PAL3, Expert2.palette->data);
    SYS_enableInts();
    SPR_initSprite(&ExpertSprites[0], (SpriteDefinition)Expert1, EXPERT_POSITION_X, EXPERT_POSITION_Y, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    SPR_initSprite(&ExpertSprites[1], (SpriteDefinition)Expert2, 0, EXPERT_POSITION_Y, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
    SubStageInt = 2;
    return TRUE;
}

Re: Passing Sprites to Functions

Posted: Tue Oct 27, 2015 11:00 pm
by Stef
matteus wrote:Is there a way I can do this?

Code: Select all

u16 loadExperts(Sprite Expert1, Sprite Expert2) {
    SYS_disableInts();
    VDP_setPalette(PAL2, Expert1.palette->data);
    VDP_setPalette(PAL3, Expert2.palette->data);
    SYS_enableInts();
    SPR_initSprite(&ExpertSprites[0], (SpriteDefinition)Expert1, EXPERT_POSITION_X, EXPERT_POSITION_Y, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    SPR_initSprite(&ExpertSprites[1], (SpriteDefinition)Expert2, 0, EXPERT_POSITION_Y, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
    SubStageInt = 2;
    return TRUE;
}
You declare Expert1 and Expert2 as Sprite then you cast them as SpriteDefinition O_o ??
It should be more like this :

Code: Select all

u16 loadExperts(SpriteDefinition *Expert1, SpriteDefinition *Expert2) {
    SYS_disableInts();
    VDP_setPalette(PAL2, Expert1->palette->data);
    VDP_setPalette(PAL3, Expert2->palette->data);
    SYS_enableInts();
    SPR_initSprite(&ExpertSprites[0], Expert1, EXPERT_POSITION_X, EXPERT_POSITION_Y, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    SPR_initSprite(&ExpertSprites[1], Expert2, 0, EXPERT_POSITION_Y, TILE_ATTR(PAL3, TRUE, FALSE, FALSE));
    SubStageInt = 2;
    return TRUE;
}