GP32 2d clipping


Hi Sprites clipping to screen is very easy here's a quick one that works very well

but this only works if you use a tile based system

OSB = off screen buffer

make the off screen buffer width and height +=(sprite size)*2
OSB.Width=Screen.Width+(SpriteTileWidth*2);
OSB.Height=Screen.Height+(SpriteTileHeight*2);

then your clipping is simply this
IF (SpriteTilePos.x<0) dont draw
IF (SpriteTilePos.x>(OSB.Width-SpriteTileWidth)) dont draw
IF (SpriteTilePos.y<0) dont draw
IF (SpriteTilePos.y>(OSB.Height-SpriteTileHeight)) dont draw

when you come to blit the OSB to the screen you simply blit the center part of the
OSB - missing out the edge.

works a treat

Check out mr spivs sprite demo - I think he does this trick in that demo
 
Surely thats:

IF (SpriteTilePos.x+SpriteTileWidth<0) dont draw
IF (SpriteTilePos.x>OSB.Width) dont draw
IF (SpriteTilePos.y+SpriteTileHeight<0) dont draw
IF (SpriteTilePos.y>OSB.Height) dont draw

?


I'd have thought with a tile based engine you wouldn't really need any clipping for the BGs, as you'd be keeping track of which tile to start from and you'd know how many tiles you need to draw horizontally and vertically?

For sprites you could keep an array of "active" sprites, i.e ones that are on screen. Once a sprite walks off screen it's removed from the array and so the engine no longer draws/clips/moves it. There's a few ways of checking if a sprite should be moved to the active array...
 
How cool clipping are we talking here?
smth like baldurs gate kind of clipping? afaik that one was pretty cool and yet kinda simple, much for handling sprite sorting etc.
There are probably some docs out there on that one.

---
mithris
 
Surely thats:

IF (SpriteTilePos.x+SpriteTileWidth<0) dont draw
IF (SpriteTilePos.x>OSB.Width) dont draw
IF (SpriteTilePos.y+SpriteTileHeight<0) dont draw
IF (SpriteTilePos.y>OSB.Height) dont draw

?

no RobG thats incorrect - that would clip as soon as the sprite went 1 pixel to the left offscreen or 1 pixel below offscreen , and would cause the sprites to wrap at the other end. The first code I gave is correct.
 
no RobG thats incorrect - that would clip as soon as the sprite went 1 pixel to the left offscreen or 1 pixel below offscreen , and would cause the sprites to wrap at the other end. The first code I gave is correct.

My mistake :)
 
Thats the kind of clipping i do too.

But you could add fuuther to that by drawing different layers at different frame intervals. like background drawn every 2 foreground draws :)
 
nope..
i'm just looking for a good and original algorithm

all those above are simply and very common

what if I was using RLE-sprites?

is there a way to clip RLE sprites?
 
Yo DM! Haven't seen you in a while!

Here's all I'd do. I know you like to use SDK, but this might not work with it. Use the LCD hardware to make a bigger buffer, and then you can just write your sprites normally, and the hardware will clip it. If you need more help, you should talk to spiv, and he'll walk you through it. If you can't get ahold of him, maybe I can help you, but I haven't done any LCD stuff for a while (around a year). Anyways, I could at least give you some source to get started. That would work with RLE sprites too, btw.
 
Yep.. If you only need to clip sprites that go outside visible screen area then reserving extra offscreen buffers are definitely the way to go. Offscreen buffers also work perfectly with RLE and compiled sprites.
 
Back
Top