Clipping a sprite

Blitz3D Forums/Blitz3D Beginners Area/Clipping a sprite

Farflame(Posted 2005) [#1]
What's the best/fastest way to clip a sprite in Blitz? I don't want to clip it off the edge of the screen, but anywhere on the screen. What I'm basically doing is showing an energy bar, which goes from red and one end, to green at the other, showing the condition of the player as a percentage. There will actually be 22 of these bars on the screen per frame so I need it to be fast.

One method I can think of is to print the entire bar, then blank out the 'black' section with a rect command, but isn't rect too slow for real-time applications (especially printing 22 of them per frame)?

Is there a simple clip method?


Rob Farley(Posted 2005) [#2]
I found the easiest way of doing this was to scale a sprite over the top of another one. Of course this will knacker any graphics you've actually got on the sprite.

The other way is to create the sprite by copyrecting onto the texture, of course this isn't as fast as it would like to be.


Thinking about it though...

You could probably do some funky thing using 2 quads... ie |\|\| type affair (if you get what I mean)

Have a texture where the top half is the 'off' texture and the bottom half is the 'on' texture.
Now, apply the top half of the texture to the left hand quad and the bottom half of the texture to the right hand quad.
Then move the middle line (between the quads left and right) based on the health of the bar.
You will also have to do some funky stuff about realigning the UVs but that won't be hard... That might just work you know!


Farflame(Posted 2005) [#3]
Err sorry, I should have pointed out that I'm talking about 2d sprites only. I realise I've used the 3d section of the forum - because there isn't a 2d section, and I'm using B3D. Sorry about that :/


Farflame(Posted 2005) [#4]
No worries, resolved this one. There's a 'drawimagerect' command I didn't know about :)


Ross C(Posted 2005) [#5]
Use the word image instead of sprite ;o)

That drawimagerect is super handy for stuff like that :D


big10p(Posted 2005) [#6]
If your bar images don't have any masked pixels, you can use DrawBlockRect instead, for a slight speed-up.