Passing Sprites to Functions

SGDK only sub forum

Moderator: Stef

Post Reply
matteus
Very interested
Posts: 336
Joined: Mon Feb 04, 2008 1:41 pm

Passing Sprites to Functions

Post by matteus » Tue Oct 27, 2015 9:25 pm

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;
}

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Passing Sprites to Functions

Post by Stef » Tue Oct 27, 2015 11:00 pm

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;
}

Post Reply