GLBasic forum

Feature request => 2D => Topic started by: spicypixel on 2012-Apr-24

Title: Pixel Collision with Rotated Sprites
Post by: spicypixel on 2012-Apr-24
Seems an obvious one to me but having SPRITE and ANIM COLL that works on the ROTATED sprite would be cool rather than based on the original sprite.
Title: Re: Pixel Collision with Rotated Sprites
Post by: Ian Price on 2012-Apr-24
It was suggested years ago.

There are work arounds, although none as smooth or as elegant as a built in rotation collision commands.

In one game I did (Balloonacy for Wiz, GP2X and pc) I drew my roto'd sprite in real-time onto a virtual sprite and used that for collision checking. Worked really well, even on a GP2X. I wouldn't recommend this for lots of roto-collsions though.

The alternative is to pre-render all rotations (if possible) - either as a spritesheet or at the start of the code.
Title: Re: Pixel Collision with Rotated Sprites
Post by: spicypixel on 2012-Apr-24
Had already thought of pre-rendering as it's a technique I have used before sprite rotation was even quick enough on certain other languages :D However firstly don't like the memory overhead especially for a smooth rotation and secondly it should be in there. A real oversight to have roto commands and no roto related collision. Will have to continue making ball games lol.
Title: Re: Pixel Collision with Rotated Sprites
Post by: Ian Price on 2012-Apr-24
If you don't like pre-rendering then the virtual screen in real-time is the only option right now.
Title: Re: Pixel Collision with Rotated Sprites
Post by: Slydog on 2012-Apr-24
I've been noticing that a lot of commercial games don't use pixel-perfect collision detection.

It would be cool to have a new feature (or create a sprite library) that offers adding (multiple?) colliders to sprites.
The basic circular and rectangular colliders would probably be enough for most games.

For example, a typical car sprite, with a body and two wheels:  (total size is 128x64)
Code: (glbasic) [Select]
car.AddCollider_Box(0,0,  128,32)   // Main body - top half of sprite
car.AddCollider_Circle(32,48, 16)   // Left Wheel, radius 16
car.AddCollider_Circle(96,48, 16)   // Right Wheel, radius 16

And then have these colliders scale and rotate with the sprite.
Should be much faster and simpler to implement than pixel perfect sprite scaling and rotations.

Just a 'dream' request of course! 
One day I may create my own 2D sprite library, but not any time soon!
Title: Re: Pixel Collision with Rotated Sprites
Post by: Kitty Hello on 2012-Apr-24
a Sprite is just a bitmap in memory. With GETSPRITESIZE you have all information at hands.
So, you can write: SPRCOLL_box() and SPRCOLL_sphere() easily yourself.