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 > Pern sprite question

#35643 - WillyWonka - Tue Feb 08, 2005 9:21 pm

I'm going through the pern tutorials and I can't seem to figure something out. In the init function, it goes through and turns all the sprites off.

Code:
   for(i = 0; i < 128; i++)
      OAMCopy[i].attribute[0] = SPRITE_OFF;

(#define SPRITE_OFF BIT9)

Which command turns the sprites back on?

#35649 - sajiimori - Tue Feb 08, 2005 11:29 pm

Don't think about it as a command that turns sprites off. Think about it as storing a value in an array. The array just happens to be OAM, and the GBA later reads from it to decide how to draw sprites.

Continue reading pern to discover why storing that value causes the sprite to not be drawn, then keep reading to find out what other values you can store that will have other effects. Pern will tell you the purpose of every bit of every attribute.

If you run into problems during your reading, feel free to ask here. ^_^

#36133 - virgo24 - Tue Feb 15, 2005 6:49 am

Use this to change the hide/show state of a sprite...
Code:
OAMCopy[myspriteindex].attribute[0] ^= SPRITE_OFF;

#36188 - yaustar - Tue Feb 15, 2005 9:38 pm

What is the value of SPRITE_OFF? IF I remember correctly tepples mentioned a method that tells the gba not to process the sprite if the rotation bit is off (0) and double sized is enabled (1).

However there are easier ways to make a sprite 'disappear' as sajiimori(sp?) is suggesting ;)
_________________
[Blog] [Portfolio]

#36189 - sajiimori - Tue Feb 15, 2005 9:57 pm

virgo24, your code is wrong. WillyWonka's original code works because it clears all the other bits.

There is no "sprite off" bit. yaustar is right about rotation and double size.

#36641 - ymalik - Sat Feb 26, 2005 8:15 pm

You can also move the sprite offscreen to turn it ``off.''

#36644 - tepples - Sat Feb 26, 2005 8:49 pm

ymalik wrote:
You can also move the sprite offscreen to turn it ``off.''

True, but some claim that if a sprite is horizontally offscreen, it still consumes rendering cycles and can cause dropouts in other sprites on the same scanline. And if a sprite is 32x64 or 64x64 pixels and it's scaled double-size, you can't move it vertically offscreen. The easiest way to turn off a sprite is to set its attribute 0 to 0x0200, not using any exclusive OR modification (^=) operator, but just doing something like this:
Code:
#define SPRITE_OFF 0x0200

OAMCopy[myspriteindex].attribute[0] = SPRITE_OFF;

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.