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 > Using windows for sprites

#17762 - Lupin - Sun Mar 14, 2004 12:58 pm

How could i use windows for sprites? I googled for a tutorial about it but i wasn't able to find anything usefull...

http://www.rafb.net/paste/results/Px907073.html
that is what i got so far...

I found out that i have to use WININ and WINOUT registers, i got it work by using them. But now all sprites get windowed by my window sprite?! I only want to apply the window for a single sprite! How can i do that?

#17765 - poslundc - Sun Mar 14, 2004 2:55 pm

I don't think you can... windows apply to whatever your settings in WIN_IN/OUT are, so it's either all OBJs or no OBJs.

Dan.

#17766 - Lupin - Sun Mar 14, 2004 3:52 pm

ok, i will just render the sprite myself for every frame...

#17768 - abilyk - Sun Mar 14, 2004 4:41 pm

Unless I'm misunderstanding the question, you can specify which sprite(s) is(are) affected by the OBJ window settings. From GBATEK's reference to OBJ Attribute 0:

Quote:
10-11 OBJ Mode (0=Normal, 1=Semi-Transparent, 2=OBJ Window, 3=Prohibited)


Bits 10-11 will let you control whether a sprite uses the window settings or not.

#17770 - Lupin - Sun Mar 14, 2004 4:59 pm

thx, but it didnt help :/

#17771 - abilyk - Sun Mar 14, 2004 5:03 pm

What graphics effect are you trying to accomplish?

#17773 - Lupin - Sun Mar 14, 2004 5:28 pm

i want a top view of my terrain that gets rotated and i don't want to make it square shaped

#17776 - DekuTree64 - Sun Mar 14, 2004 6:19 pm

I think you need to take the window flag out of the second sprite. Otherwise it just becomes a second window itself, and is therefore invisible.
If you can't get that to work, use one of the regular windows and change its size on HBlank to get the same effect.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#17782 - abilyk - Sun Mar 14, 2004 6:56 pm

Hrm... looking at that code you linked in your first post, you're using mode 4? The purpose of the windowing registers is to define which layers are displayed on different portions of the screen. Since mode 4 only uses a single layer (BG 2, isn't it?), using the windowing registers won't do you a whole lot of good, I don't think.

Edit:
Upon further thought and research, I suppose using the window regs even in mode 4 could be useful. If you specified a layer other than BG2, it may just show the backdrop instead, and you can still specify the OBJ layer. I guess I still don't really understand exactly what you're trying to accomplish. Just a mini-map of the current area? Perhaps you could show us a screen mockup?


Last edited by abilyk on Sun Mar 14, 2004 7:03 pm; edited 1 time in total

#17785 - poslundc - Sun Mar 14, 2004 7:00 pm

abilyk wrote:
Unless I'm misunderstanding the question, you can specify which sprite(s) is(are) affected by the OBJ window settings. From GBATEK's reference to OBJ Attribute 0:

Quote:
10-11 OBJ Mode (0=Normal, 1=Semi-Transparent, 2=OBJ Window, 3=Prohibited)


Bits 10-11 will let you control whether a sprite uses the window settings or not.


It's my understanding that these bits determine which sprites determine the window's mask, not which sprites are actually affected by the presence of the window.

Dan.

#17786 - abilyk - Sun Mar 14, 2004 7:05 pm

poslundc wrote:
It's my understanding that these bits determine which sprites determine the window's mask, not which sprites are actually affected by the presence of the window.

Dan.


I thought differently, and if I remember right, I tested this awhile ago and the results supported my post. However, this was awhile ago, and I don't remember for certain, so you may be right. This warrants some testing, I think.

#17788 - poslundc - Sun Mar 14, 2004 7:16 pm

I've never used sprite windows so I can't say. I don't speak from experience, but rather from this thread and also the logical inference that the sprite window is useless unless you can specify which sprites form the window, so there must be some way to do so. I am not aware of any way of specifying them other than the OAM bits.

Dan.

#17789 - Lupin - Sun Mar 14, 2004 7:24 pm

hm, after thinking about it a little bit i found out that i can just draw every sprite twice (one as window and one normal), but that would be wastefull....
_________________
Team Pokeme
My blog and PM ASM tutorials

#17794 - abilyk - Sun Mar 14, 2004 9:05 pm

As I understood it, when using windows you can define which layers are visible in each window using the window registers. If you define a particular window to display the OBJ layer, it will simply display all visible sprites within the window.

So, in the case of activating OBJ window, each sprite set to "OBJ window" (in bits 10-11 of attribute 0) is not visible, but rather acts as a window (the size of that particular sprite) that displays the layers specified in the higher byte of the WINOUT register. If you specify OBJs as one of those layers, then visible sprites that overlap that particular window sprite would be shown.

I'll do a test soon to verify this.

#17795 - DekuTree64 - Sun Mar 14, 2004 9:23 pm

I think a better way would be to put the map sprite -behind- the mode4 BG, then only disable the BG in the window, the sprites are still active inside and outside. That way you can have sprites anywhere on the screen, but still get the desired effect for the one sprite.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#17797 - Lupin - Sun Mar 14, 2004 9:47 pm

i don't understand, why are you talking about BGs? And why placing sprites behind my BG? Why? :P
_________________
Team Pokeme
My blog and PM ASM tutorials

#17800 - Miked0801 - Sun Mar 14, 2004 10:30 pm

You can tell the GBA to use the sprite as a window against BGs. Any non-zero data in the sprite is considered a windows (or visa-versa - can't quite recall.) It makes it easy to do sutff like, oh the keyhole effect in Super Mario (you can also do this with hblanks, but its much more cumbersome.) We use it to do a lantern effect in dark areas. Works nice.

#17803 - abilyk - Sun Mar 14, 2004 11:45 pm

I made a test program and confirmed my earlier post:

abilyk wrote:
From GBATEK's reference to OBJ Attribute 0:

Quote:
10-11 OBJ Mode (0=Normal, 1=Semi-Transparent, 2=OBJ Window, 3=Prohibited)

Bits 10-11 will let you control whether a sprite uses the window settings or not.

All sprites that are used as sprite windows must use the same mask, specified by WINOUT.

#17804 - poslundc - Mon Mar 15, 2004 12:02 am

Uh, I think we've been saying the same thing... :P

Dan.

#17806 - abilyk - Mon Mar 15, 2004 1:44 am

You know what, I think you're right. =D

Don't you just hate that, arguing to find out you weren't really arguing at all? D'oh.

#17819 - Lupin - Mon Mar 15, 2004 1:17 pm

abilyk, so you solved my problem? If yes please post the relevant code here... i don't seem to get this work right now :(
_________________
Team Pokeme
My blog and PM ASM tutorials

#17828 - abilyk - Mon Mar 15, 2004 4:37 pm

I didn't necessarily solve your problem, but I'm sure we'd be able to help you. I still don't understand exactly what you want, though. Can you post a screenshot or a hand-made mockup showing the final result you want and the pieces you're trying to use to "build" it?

#17835 - Lupin - Mon Mar 15, 2004 5:45 pm

http://home.arcor.de/lupin003/shouldbe.gif
_________________
Team Pokeme
My blog and PM ASM tutorials

#17837 - poslundc - Mon Mar 15, 2004 6:07 pm

Simple solution: use a background instead of a sprite for your map, and apply the window to it.

More complicated solution: use the alpha register to blend sprites and your backgrounds so that the sprite's visibility is 0%. Then make sure that alpha effects are turned off inside your sprite window. Then make your map the only sprite that uses the alpha register. Of course, this means wasting your alpha register on something that can be done much easier using solution 1.

You cannot use a window to obscure some sprites and not others.

Dan.

#17843 - DekuTree64 - Mon Mar 15, 2004 9:27 pm

Ok, I finally decided to just try it myself, and indeed my solution didn't work. I was under the impression that you could set the priority of the mode4 BG, but it seems sprites are always infront of it nomatter what priority settings you use.
If you want to use any sprites other than the radar, I think you'll have to just render it in software each frame. It may be a little slow witht he voxel rendering soaking up so much time already, but I can't think of any other way.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#17858 - abilyk - Tue Mar 16, 2004 2:11 am

Ok, I can think of a couple solutions. First, to clarify what won't work, you're working in mode 4 out of necessity for a bitmap mode, so you can't use a background for the radar. As Deku mentioned, you could render the sprites in software, but that would be slow, perhaps too slow. Here are my ideas:

1) Manually make the sprite a circle instead of a rectangle. I know the rectangle is the initial format of your sprite, but each frame you could copy transparent "pixels" into the sprite's image cel in VRAM, essentially "shaving" the rectangle into a circle. You'd only need to alter about 200 pixels, which should be a quick and dirty job.

2) More fun with windows. This solution would cut off any of your in-game sprites that overlap with your radar's bounding box, but that may be acceptable to you. As shown here ([Images not permitted - Click here to view it]), set Window 1 to the dimensions of the radar sprite. Turn off sprites in Window 1, but turn on everything else. Turn on everything in the Outside Windows (the rest of the screen). Your radar sprite will not be shown inside Window 1, since sprites are turned off. Now, activate the Sprite window, turning on sprites, and set your circle window sprite over your radar. That should do it, I think.

- Andrew

#17863 - ScottLininger - Tue Mar 16, 2004 4:55 am

Alpha blending may be the answer...

But it's really hard to explain what I'm thinking. I guess I'll just dive in:

It looks from your mockup like you'd just need two 32x32 sprites: One that contains your map and one that contains a NEGATIVE mask. (I'll explain what I mean by that in a second)

The map sprite would be behind the mask sprite (i.e. the map would have a larger OAM index)

The mask sprite would be a white square with a black circle in the middle. (The colors are actually unimportant... but when I say BLACK I mean palette index 0, or a transparent circle) The white "rim" around the circle would obviously block out the parts of the map you don't want to see.

Here's where the magic comes in: if you set the mask sprite to be alpha blended, then set the alpha register to 100% invisible, the white parts of the circle would STILL block out the edges of the map, but visually the player would see the mode4 background instead of white.

It's just a goofy thing about alpha blending: sprites in front will block out sprites in back, even if the top sprite is 100% invisible. However, truly transparent pixels (palette index 0) in the top sprite will allow things to show through.

If you need code to do this, let me know and I can post a simple function that shows you what I mean.

#17869 - poslundc - Tue Mar 16, 2004 5:58 am

Dude, I said the exact same thing three posts up. :P

Dan.

#17871 - ScottLininger - Tue Mar 16, 2004 7:14 am

Quote:
Dude, I said the exact same thing three posts up. :P


Dan, I'm actually not sure we're talking about the same thing... You said:

Quote:
More complicated solution: use the alpha register to blend sprites and your backgrounds so that the sprite's visibility is 0%. Then make sure that alpha effects are turned off inside your sprite window. Then make your map the only sprite that uses the alpha register.


I'm not talking about using windowing (or shall I say, the window registers). It should work without windowing if you use a sprite for your "mask". And the map would not use the alpha register, the mask sprite would.

Of course, this may be more a challenge of vocabulary than actual concept. Perhaps by "sprite window" you mean the lower-index sprite that's on top (what I'm calling the mask), and by "map" you mean the whole construct. Gah! :)

#17882 - poslundc - Tue Mar 16, 2004 3:02 pm

You're right, we were talking about slightly different ideas.

Be careful, though: while yours makes sense in theory, it might run into problems when tried on hardware. According to this thread, sprites obscured by other alpha-blended sprites may cause undesirable screen artifacts.

Dan.