Page 1 of 1

Scroll map region corruption

Posted: Wed Oct 07, 2015 12:33 am
by orlanrod
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();

}

Re: Scroll map region corruption

Posted: Wed Oct 07, 2015 2:13 am
by djcouchycouch
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?

Re: Scroll map region corruption

Posted: Wed Oct 07, 2015 2:52 am
by orlanrod
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.

Re: Scroll map region corruption

Posted: Wed Oct 07, 2015 8:25 am
by Stef
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 :)

Re: Scroll map region corruption

Posted: Wed Oct 07, 2015 6:37 pm
by orlanrod
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?

Re: Scroll map region corruption

Posted: Wed Oct 07, 2015 8:22 pm
by Stef
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 ;)