Clearing plans and texts.

SGDK only sub forum

Moderator: Stef

Post Reply
orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Clearing plans and texts.

Post by orlanrod » Mon Oct 12, 2015 6:57 pm

I'm using VDP_clearPlan and VDP_cleartext, but their seems to be left over text from the title screen.

It clears the Background title, and the title logo. Also clears "Play" text but not "Options"

here is the code.

VDP_clearText(18, 19, 40);
VDP_clearText(16, 20, 40);
VDP_clearPlan(APLAN, TRUE);
VDP_clearPlan(BPLAN, TRUE);

nolddor
Very interested
Posts: 102
Joined: Sun Jun 02, 2013 1:35 pm
Location: Spain

Re: Clearing plans and texts.

Post by nolddor » Tue Oct 13, 2015 1:11 pm

How do you print the "options" string?

orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Re: Clearing plans and texts.

Post by orlanrod » Tue Oct 13, 2015 5:44 pm

nolddor wrote:How do you print the "options" string?
Using the function i wrote. The options text is the second vdp_drawtext line in drawGameTxt()

char* getGameTxt(int txtnum, int txtnumtwo)
{
mytxt[0][0] = "PLAY";
mytxt[1][0] = "OPTIONS";
return (mytxt[txtnum][txtnumtwo]);
}

void drawGameTxt()
{
if (loc == 1) VDP_drawText(getGameTxt(0,0), 18, 19); VDP_drawText(getGameTxt(1,0), 16, 20);
}

drawGameTxt is in main like this

while(TRUE)
{
entityInput();
entityAnim();
updateCamera();
drawGameTxt();

VDP_waitVSync();
}

And this is what triggers the events. assetLoader is another one of my functions.

static void joyEvent(u16 joy, u16 changed, u16 state)
{

if (changed & state & BUTTON_START)
{
if (loc == 1) loc++; assetLoader(loc);
}
}


void assetLoader(int pack)
{
if (pack == 1)
{
titlebgmap = unpackMap(titlebg_tiles.map, NULL);
ind = TILE_USERINDEX;
VDP_loadTileSet(titlebg_tiles.tileset, ind, TRUE);
VDP_setMapEx(BPLAN, titlebgmap, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
ind += titlebg_tiles.tileset->numTile;

titlelogomap = unpackMap(titlelogo_tiles.map, NULL);
VDP_loadTileSet(titlelogo_tiles.tileset, ind, TRUE);
VDP_setMapEx(APLAN, titlelogomap, TILE_ATTR_FULL(PAL3, FALSE, FALSE, FALSE, ind), 10, 1, 0, 0, 20, 17);
ind += titlelogo_tiles.tileset->numTile;
}

if (pack == 2)
{
ind = 0;
SYS_disableInts();
VDP_clearText(18, 19, 40);
VDP_clearText(16, 20, 40);
VDP_clearPlan(APLAN, TRUE);
VDP_clearPlan(BPLAN, TRUE);
SYS_enableInts();
// init jaris sprite
player1.hmirror = 0;
player1.vmirror = 0;
player1.zorder = 0;
player1.x = 150;
player1.y = 150;
player1.current_frame = 0;
player1.current_anim = ANIM_STANDSIDES;
player1.animspeeds[0] = 50;
player1.animspeeds[1] = 20;
player1.animspeeds[2] = 2;
//Citizen vars
cxypos[0][0] = 160;
cxypos[1][0] = 150;
czorder = 1;
VDP_setPalette(PAL0, sjaris_sprite.palette->data);
VDP_setPalette(PAL1, fcitizen_sprite.palette->data);
VDP_setPalette(PAL2, city_tiles.palette->data);
SPR_initSprite(&sprites[player1.zorder], &sjaris_sprite, player1.x, player1.y, TILE_ATTR(PAL0, TRUE, FALSE, FALSE));
SPR_initSprite(&sprites[czorder], &fcitizen_sprite, cxypos[0][0], cxypos[1][0], TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_update(sprites, 0);
SPR_update(sprites, 1);
citymap = unpackMap(city_tiles.map, NULL);
ind = TILE_USERINDEX;
VDP_loadTileSet(city_tiles.tileset, ind, TRUE);
VDP_setMapEx(BPLAN, citymap, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
ind += city_tiles.tileset->numTile;
}

}

orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Re: Clearing plans and texts.

Post by orlanrod » Tue Oct 13, 2015 5:55 pm

I have discoverd the issue, and fixed it by dumb luck.

This

if (loc == 1) VDP_drawText(getGameTxt(0,0), 18, 19); VDP_drawText(getGameTxt(1,0), 16, 20);

Was changed to this.

if (loc == 1)
{
VDP_drawText(getGameTxt(0,0), 18, 19);
VDP_drawText(getGameTxt(1,0), 16, 20);
}

Why did it not work the first way?

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Clearing plans and texts.

Post by mikejmoffitt » Tue Oct 13, 2015 8:03 pm

I'm not sure, but your first syntax was absolute insanity so it's good to see the clean option worked better :P

orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Re: Clearing plans and texts.

Post by orlanrod » Tue Oct 13, 2015 9:03 pm

mikejmoffitt wrote:I'm not sure, but your first syntax was absolute insanity so it's good to see the clean option worked better :P
Yeah, it is strange. Thinking how that would even conflict with the clearing of text.
Usually i see people negate the curly braces if it can run on a single line, so i thought i should do it to.

There is a blog video coming on Saturday. Showing off the progress and a walk through my crap code. 8P

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

Re: Clearing plans and texts.

Post by Stef » Wed Oct 14, 2015 8:33 am

You need braces as soon you have more than 1 "instruction" (or operation) so here :

Code: Select all

if (loc == 1) VDP_drawText(getGameTxt(0,0), 18, 19); VDP_drawText(getGameTxt(1,0), 16, 20);
Only the first VDP_drawText(..) call is affected by the condition, second call is always executed whatever is loc.
As a general good practice is to always use the brace so you know what is affected by condition ;)

orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Re: Clearing plans and texts.

Post by orlanrod » Wed Oct 14, 2015 5:54 pm

Stef wrote:You need braces as soon you have more than 1 "instruction" (or operation) so here :

Code: Select all

if (loc == 1) VDP_drawText(getGameTxt(0,0), 18, 19); VDP_drawText(getGameTxt(1,0), 16, 20);
Only the first VDP_drawText(..) call is affected by the condition, second call is always executed whatever is loc.
As a general good practice is to always use the brace so you know what is affected by condition ;)
Ah okay. Yeah i see that now. Thanks! <8B

Post Reply