Scroll map region corruption

SGDK only sub forum

Moderator: Stef

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

Scroll map region corruption

Post by orlanrod » Wed Oct 07, 2015 12:33 am

So, i was trying to make it scroll less then 8 pixels by changing the xscroll to a float, but now i have a new problem. (still doesn't scroll less than 8 pixels, don't know what to do)

The graphics corrupt while i have scrollx going, and the player is passing above or bellow the npc to trigger the zorder change.
I don't think it's because i switch to a float, but that i switch sprite array order while its scrolling. What you think it could be?
Here is the code.

Code that switches zorder.

if (player1.posy > cxypos[1][0])
{

if (triggerIndex == 1)
{
player1.pzorder = 0;
czorder = 1;
SPR_initSprite(&sprites[player1.pzorder], &jason_sprite, player1.posx, player1.posy, TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_initSprite(&sprites[czorder], &fcitizen_sprite, cxypos[0][0], cxypos[1][0], TILE_ATTR(PAL2, TRUE, FALSE, FALSE));

triggerIndex = 0;
}

}
else
{

if (triggerIndex == 0)
{
player1.pzorder = 1;
czorder = 0;
SPR_initSprite(&sprites[player1.pzorder], &jason_sprite, player1.posx, player1.posy, TILE_ATTR(PAL1, TRUE, FALSE, FALSE));
SPR_initSprite(&sprites[czorder], &fcitizen_sprite, cxypos[0][0], cxypos[1][0], TILE_ATTR(PAL2, TRUE, FALSE, FALSE));

triggerIndex = 1;
}

}


Map scrolling code.

if (tileproperty == TILEPROP_NOTSOLID) { scrollH = 1; } else { scrollH = 0; }

if ((value & BUTTON_RIGHT) && MapXPosInTile < 152 && scrollH == 1 )
{
SYS_disableInts();
MapXPosInTile += 0.1;
pInMAX = (player1.posx/16)+MapXPosInTile;
cxypos[0][0] -= 0.1;
SPR_setPosition(&sprites[czorder], cxypos[0][0], cxypos[1][0]);
indb = TILE_USERINDEX;
VDP_setMapEx(BPLAN, map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, indb), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
indb += bgb_image.tileset->numTile;
SYS_enableInts();

}

if ((value & BUTTON_LEFT) && MapXPosInTile > 0 && mright != 1 && scrollH == 1 && tileproperty == TILEPROP_NOTSOLID)
{

SYS_disableInts();
MapXPosInTile -= 0.1;
pInMAX = (player1.posx/16)+MapXPosInTile;
cxypos[0][0] += 0.1;
SPR_setPosition(&sprites[czorder], cxypos[0][0], cxypos[1][0]);
indb = TILE_USERINDEX;
VDP_setMapEx(BPLAN, map, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, indb), PlanXPosInTile, PlanYPosInTile, MapXPosInTile, MapYPosInTile, MapWidthInTile, MapHeightInTile);
indb += bgb_image.tileset->numTile;
SYS_enableInts();

}

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Re: Scroll map region corruption

Post by djcouchycouch » Wed Oct 07, 2015 2:13 am

You can try commenting out section by section to narrow down which part is causing the problem.

By corruption, what gets affected? sprites, backgrounds or both? Are the graphics random garbage or just the wrong tiles?

Can you provide a screenshot?

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

Re: Scroll map region corruption

Post by orlanrod » Wed Oct 07, 2015 2:52 am

djcouchycouch wrote:You can try commenting out section by section to narrow down which part is causing the problem.

By corruption, what gets affected? sprites, backgrounds or both? Are the graphics random garbage or just the wrong tiles?

Can you provide a screenshot?
Full screen visual corruption, of random garbage. I'll see if i can record it and upload to youtube. I'm going to do a video log anyways.

Probably was that float. I switched it back to regular int and it's not doing the problem. But now i am back to square one, and it's still scrolls 8 pixels at a time. Also my animation code seems to cause the screen to flicker twice every so often with the idle animation.

Now it seems i got it to corrupt (well black out) with int as well if i switch zorder quickly. I think i am doing to much, with the scrolling and the zorder code.

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

Re: Scroll map region corruption

Post by Stef » Wed Oct 07, 2015 8:25 am

Did you actually tried to use "float" type in your code ? They are not really supported (i don't think SGDK compiler even include the float emulation API) and if they are, they will be damn slow so you really need to avoid any "float" or "double" declarations.

SGDK has sort of fixed point support type to help with mathematical stuff :
https://github.com/Stephane-D/SGDK/wiki/Tuto-Maths

So use fix16 or fix32 instead of float :)

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

Re: Scroll map region corruption

Post by orlanrod » Wed Oct 07, 2015 6:37 pm

Stef wrote:Did you actually tried to use "float" type in your code ? They are not really supported (i don't think SGDK compiler even include the float emulation API) and if they are, they will be damn slow so you really need to avoid any "float" or "double" declarations.

SGDK has sort of fixed point support type to help with mathematical stuff :
https://github.com/Stephane-D/SGDK/wiki/Tuto-Maths

So use fix16 or fix32 instead of float :)
Yep, i used float lol.

But how do you make it scroll less then 8 pixels? the map does not seem to budge until it gets to int values, 1,2,3,4 etc
Or its how the mapex works?

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

Re: Scroll map region corruption

Post by Stef » Wed Oct 07, 2015 8:22 pm

You have to use the hardware scrolling capabilities :

Code: Select all

void VDP_setHorizontalScroll(VDPPlan plan, s16 value);
I really encourage you to read more about how work the Megadrive video system as that is basic feature of it ;)

Post Reply