Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2017-09-29 11:01:38

Mills
Member
Registered: 2012-12-21
Posts: 122

How to set Sprite Flags

Well I was playing with sprite flags, and as I'm not a very skilled programer I found some difficulties.

Code:

/* 
Sprite properties bits (0x00)
PALETTE NUBER    0x0_  // being "_" =  0-7
FLIPX        0x20
FLIPY        0x40
BEHIND BKG   0x80
*/

//gbdk usage
set_sprite_prop(spritenumber,0x00);

Now I want sprite 0 to use palette 1 and flip it around X axis:

Code:

set_sprite_prop(0,0x01);    
set_sprite_prop(0,0x20);

That will reset the palette to 0 so:

Code:

set_sprite_prop(0,0x21);

That flips it and sets palette 1, so I can mix the flip x and palette properties just fine.

Then imagine I want to set the sprite behind the last 3 colours of the bkg palettes:

Code:

set_sprite_prop(0,0x21);
set_sprite_prop(0,0x81);

I just can't do it this way, because the flip x flag will be reset to 0, so the sprite will go behind the bkg, but with wrong flip.

What's the proper way to add these properties? Do I have to use assembly to mix them?.

Last edited by Mills (2017-09-29 11:03:59)

Offline

 

#2 2017-09-29 11:30:43

tbsp
Member
Registered: 2017-03-16
Posts: 12

Re: How to set Sprite Flags

I believe this is what you're after:

Code:

set_sprite_prop(0,0xA1);

0x01 + 0x20 + 0x80 = 0xA1

Offline

 

#3 2017-09-29 11:58:11

Mills
Member
Registered: 2012-12-21
Posts: 122

Re: How to set Sprite Flags

tbsp wrote:

I believe this is what you're after:

Code:

set_sprite_prop(0,0xA1);

0x01 + 0x20 + 0x80 = 0xA1

I was about to try that, But I din't think it wiould work that way (it worked).

Thanks.

Offline

 

#4 2017-09-29 22:07:12

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 112
Website

Re: How to set Sprite Flags

It would be 0x01 | 0x20 | 0x80 rather than "+" (0x21 | 0x81 == 0xA1, 0x21 | 0x81 = 0xA2 != 0xA1). Hope you see the point.
(His answer is still right, in this case)


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#5 2017-10-02 13:20:27

tbsp
Member
Registered: 2017-03-16
Posts: 12

Re: How to set Sprite Flags

Sure, if you're trying to combine 0x21 and 0x81 that's true. | is certainly a more robust way to think about it.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson