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.

Coding > sprites and screen position problem

#21378 - dXtr - Fri May 28, 2004 10:55 am

Hi. I got this problem in a game that I together with some classmates are doing. It's a sidescrolling game and the problem occurs when the enemys passes screeen x (and maybe y... haven't test that one yet) coordinate 0 so it's -1 or other minus value. then they sprite just disappears directly instead of disappearing pixel by pixel. How do you fix this?

Explanation ascii image ;D

x pos = 0
-----------
| o
|-|-
|/ \

x pos = -1
------------
|
| * sprite gone *
|


how I want it to be:
x pos = 0
-----------
| o
|-|-
|/ \

x pos = -1
-----------
|o
||-
| \

x pos = -2
-----------
|
|-
|\

and so on..

#21379 - DigitalChaos - Fri May 28, 2004 11:06 am

You're gonna have to create different sprites for each position you want to show. And you're gonna want to make a state for each sprite.



x pos = 0, state 0
-----------
| o
|-|-
|/ \


for that one, you'll have full body sprite set at 0 on x axis and it's in it's first state which it will be in the entire time it's on screen until it reaches the edges.

x pos = -1, state 1
-----------
|o
||-
| \


when you are at state 0 and you move left, change the sprite to state 1 sprite and move position to 0. When in this state, if they move left again, go to state 2, or if they move right, go to state 0.

x pos = -2, state 2
-----------
|
|-
|\

This sprite would show when you move left from state 1.


I'm pretty new to all this myself, but that should work in theory.

#21380 - wintermute - Fri May 28, 2004 11:35 am

digitalChaos: don't talk complete and utter nonsense.

the sprite is probably disappearing because you haven't limited the x co-ordinate to 9 bits when setting the appropriate attribute.

Sprite[n].attr1 = (Sprite[n].attr1 & 0xfe00) | (x & 0x01ff);

#21381 - dXtr - Fri May 28, 2004 11:37 am

yeah that could work.. only problem is that then I need to create
32 sprites per animation frame?

Maybe I could do it all with code.. but wouldn't that steal some cpu?

#21382 - dXtr - Fri May 28, 2004 11:39 am

wintermute wrote:
digitalChaos: don't talk complete and utter nonsense.

the sprite is probably disappearing because you haven't limited the x co-ordinate to 9 bits when setting the appropriate attribute.

Sprite[n].attr1 = (Sprite[n].attr1 & 0xfe00) | (x & 0x01ff);


yeah I guess thats the reason to and when I hit -1 it all gets f**ed up cuz of the representation of a minus value in binary

edit:
sorry, didn't read through the whole message =/
now I have.. and it works now!! thanks! ^_^

#21386 - Akolade - Fri May 28, 2004 3:41 pm

Ya it will do that for X and Y.
The pernproject tutorials explain it fairly well.

#21389 - DigitalChaos - Fri May 28, 2004 5:34 pm

wintermute wrote:
digitalChaos: don't talk complete and utter nonsense.

the sprite is probably disappearing because you haven't limited the x co-ordinate to 9 bits when setting the appropriate attribute.

Sprite[n].attr1 = (Sprite[n].attr1 & 0xfe00) | (x & 0x01ff);



oops... :(

it was 3:45am and it sounded reasonable at the time

#21401 - dagamer34 - Fri May 28, 2004 8:09 pm

wintermute wrote:
digitalChaos: don't talk complete and utter nonsense.

the sprite is probably disappearing because you haven't limited the x co-ordinate to 9 bits when setting the appropriate attribute.

Sprite[n].attr1 = (Sprite[n].attr1 & 0xfe00) | (x & 0x01ff);


No need to attack people. Just point out their mistakes. You never know, he might have been drunk. :)
_________________
Little kids and Playstation 2's don't mix. :(

#21410 - sajiimori - Fri May 28, 2004 9:56 pm

If somebody is talking nonsense, it's ok to point that out without trying to make it sound nice. If you carefully read what wm said, you'll notice that he didn't attack dC at all -- he just said stop doing it, and I agree that he should.

Sometimes I get carried away and think I know something about everything, and end up posting a response to a question that I know nothing about. If I'm talking such nonsense that somebody has to point it out to me forcefully, that's a failure for me, and that person is doing me a big favor.

#21427 - DigitalChaos - Sat May 29, 2004 1:10 am

It's alright, I gotta learn somehow. Might as well learn from people who know what they're talking about :p

#21458 - tepples - Sat May 29, 2004 3:56 pm

When you set a sprite to show at y=-1 or x=-1 without masking off the upper bits of the position, you're screwing up the other bits in the same attribute. This may cause your sprite to disappear.

To set a sprite to show at x=-1, set it to x=511.

To set a sprite to show at y=-1, set it to y=255.

Read the CowBite spec's description of OAM for more information.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.