gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Sprites at minus positions.

#10320 - cooky - Tue Sep 02, 2003 12:36 pm

The problem is that when the sprite reaches either minus numbers on the x or y co-ordinates it starts going wrong. On the x minus position it turns into a 64 square sprite where it should be a 32 square sprite. on the y minus positions it disappears. Where am I going wrong? my only Idea is that when the move of the top or bottom of the screen you don't move the sprite of but move the pixels in the sprite to make it seem like it's moving off but that will be slow as it means updating memory every move.
any surgestions on how to get round the problem.

#10324 - Sweex - Tue Sep 02, 2003 2:30 pm

If you want sprites appearing half drawn on the left side of the screen, they should be set to the absolute position (512) minus the position. So if you want it on a horizontal position -2, you have to set it to 512 - 2 = 510...
_________________
If everything fails, read the manual: If even that fails, post on forum!

#10347 - Geno - Wed Sep 03, 2003 12:16 am

Yeah, it's one of many weird GBA quirks.
_________________
Out of Order.

#10353 - cooky - Wed Sep 03, 2003 10:08 am

I've tried what you said for the left side and it still does the same it seems. Heres the code for it.

if (mes.x < 0)
mes.x +=512;
if (mes.x > 512)
mes.x -= 512;

where am I going wrong

#10358 - cooky - Wed Sep 03, 2003 12:08 pm

Oh wait it does work it's just the rest of my program that didn't. Sigh
;)

#10380 - tepples - Wed Sep 03, 2003 5:16 pm

cooky wrote:
if (mes.x > 512)
mes.x -= 512;

where am I going wrong

Off by one. Trace the code manually with mes.x set to 512 and see what breaks.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10451 - cooky - Fri Sep 05, 2003 2:34 pm

Oh and I worked out that for the y axis this works best.

If (y < 0)
y+= 255;

If (y > 255)
y-= 255;

Oh and it should be....

if (mes.x > 511)
mes.x -= 512;

.......I think tepples point is. If I'm understanding you correctly.

Does that mean that the above should be.....

If (y > 254)

??

#10455 - tepples - Fri Sep 05, 2003 2:54 pm

cooky wrote:
Oh and I worked out that for the y axis this works best.

If (y < 0)
y+= 255;

If (y > 255)
y-= 255;

Actually, the += and -= statements should say 256 instead. (The if statements are correct.)

Quote:
Oh and it should be....

if (mes.x > 511)
mes.x -= 512;

.......I think tepples point is. If I'm understanding you correctly.

That one's correct.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10640 - Master Mofo - Thu Sep 11, 2003 12:41 pm

Do not forget that negative numbers are not allowed in the Attributes 0 and 1. they are unsigned registers.
_________________
"You have to finish what you have started"