Author Topic: Pixel Collision with Rotated Sprites  (Read 3291 times)

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Pixel Collision with Rotated Sprites
« 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.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4133
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Pixel Collision with Rotated Sprites
« Reply #1 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.
I came. I saw. I played.

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Pixel Collision with Rotated Sprites
« Reply #2 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.
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4133
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Pixel Collision with Rotated Sprites
« Reply #3 on: 2012-Apr-24 »
If you don't like pre-rendering then the virtual screen in real-time is the only option right now.
I came. I saw. I played.

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 929
  • KodeSource
    • View Profile
    • KodeSource
Re: Pixel Collision with Rotated Sprites
« Reply #4 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!
« Last Edit: 2012-Apr-24 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10667
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Pixel Collision with Rotated Sprites
« Reply #5 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.