Collisions with rotated sprites

Advanced game related topics
KeithTX
New User
New User
Posts: 4
Joined: Mon Sep 14, 2015 1:35 am

Collisions with rotated sprites

Post by KeithTX »

Is it possible to use SpriteCollision or SpritePixelCollision with a rotated sprite?

Thanks,
KeithTX
KeithTX
New User
New User
Posts: 4
Joined: Mon Sep 14, 2015 1:35 am

Re: Collisions with rotated sprites

Post by KeithTX »

Okay, I'll assume that's a no then.

-Keith
juankprada
User
User
Posts: 62
Joined: Tue Mar 18, 2014 4:25 pm
Location: Bogotá, Colombia

Re: Collisions with rotated sprites

Post by juankprada »

Instead of assuming, why dont you try it yourself?.

It isnt that difficult to load an sprite, rotate it and check for a collision with some other sprite.

Havent tried it myself but I am guessing that it works fine
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Collisions with rotated sprites

Post by DontTalkToMe »

juankprada wrote:Instead of assuming, why dont you try it yourself?.
I agree but it should be specified in the docs, else you have to assume or try.
juankprada wrote: Havent tried it myself but I am guessing that it works fine
Neither did I but based on an extrapolating hunch I would bet it doesn't work.

The OP will let us know for sure. :D
box_80
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Sep 03, 2012 8:52 pm

Re: Collisions with rotated sprites

Post by box_80 »

I have not tried myself also, but here my two cents on the subject.

SpriteCollision compares the rectangular areas around the sprites and would not rotate with the sprite. If the sprite is box shape, rotating may not make much a different.

SpritePixelCollision compares the pixels, so it should work even with a rotate sprite.
KeithTX
New User
New User
Posts: 4
Joined: Mon Sep 14, 2015 1:35 am

Re: Collisions with rotated sprites

Post by KeithTX »

juankprada: Instead of assuming I didn't try, try asking if I tried.

I did try, and no it doesn't work. Perhaps I should have asked "Is there a way to use SpriteCollision or SpritePixelCollision with a rotated sprite", I take the blame for that.

PureBasic creates the mask (be it rectangle or pixel based) when a sprite is loaded, and doesn't seem to update it if the sprite is rotated. I would venture to guess the same is true if a sprite is transformed, though I didn't try that.

-Keith
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: Collisions with rotated sprites

Post by DontTalkToMe »

KeithTX wrote: PureBasic creates the mask (be it rectangle or pixel based) when a sprite is loaded, and doesn't seem to update it if the sprite is rotated. I would venture to guess the same is true if a sprite is transformed, though I didn't try that.
Yes, you should have said that. :wink:

But thank you for reporting back the result of your test. :)

I just knew it, yeeeeeeeeeeeeah, and without trying ! The power of the extrapolating hunch ! :wink:

My sprite library does it *giggle* :mrgreen:

Maybe you can ask for it in the requests forum
KeithTX
New User
New User
Posts: 4
Joined: Mon Sep 14, 2015 1:35 am

Re: Collisions with rotated sprites

Post by KeithTX »

DontTalkToMe wrote:
KeithTX wrote: I just knew it, yeeeeeeeeeeeeah, and without trying ! The power of the extrapolating hunch ! :wink:
I applaud your extrapolating hunch. :)

I thought about extending my pb sprite animation code to handle collisions, but I think I'll just go back to C and the AGK2 lib for now.

Keith
juankprada
User
User
Posts: 62
Joined: Tue Mar 18, 2014 4:25 pm
Location: Bogotá, Colombia

Re: Collisions with rotated sprites

Post by juankprada »

DontTalkToMe wrote: My sprite library does it *giggle* :mrgreen:
Is your sprite library available somewhere?
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: Collisions with rotated sprites

Post by mpz »

Hi KeithTX,

I have mad a little PB test code and it looks like that sprite collison is not working with rotated sprite. It is not easy to programming a (Pixel-) Sprite collision of rotated sprite. Why i know that? Because my mp3d engine has a self made sprite engine with rotate sprites (and parent kid funktion) collision check.

P.S. If you have a good rotate sprite collison check i will have a look on it. I am searching for good codes to integrated them in mp3d..

Greetings Michael

PB testcode for rotate sprites collision check

Code: Select all

If InitMouse() =0  Or InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf
  
#Window = 0
If OpenWindow(#Window, 50, 200, 800, 600,"Sprite test",#PB_Window_SystemMenu | #PB_Window_SizeGadget)
  If OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window))  
  
  LoadSprite(0, "Data/PureBasic.bmp", #PB_Sprite_PixelCollision)
  CopySprite(0,1,#PB_Sprite_PixelCollision)
  
  Repeat
    
    Event = WindowEvent()
    ExamineMouse()                      
          
    x = MouseX()                         ; Returns actual x pos of our mouse
    y = MouseY()  
    ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
    
    FlipBuffers()
    
    ClearScreen(RGB(0,0,0))
    
    winkel.f + 1
    
    DisplaySprite(0, x,y)
    DisplaySprite(1, 200, 300)
    RotateSprite(1, winkel.f,#PB_Absolute)
    
    Debug SpritePixelCollision(0, x, y, 1, 200, 300)
    
    ExamineKeyboard()
  Until KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error", "Can't open a 800*600 - 32 bit screen !", 0)
EndIf
EndIf
End   

Example of mp3d
Image
Working on - MP3D Library - PB 5.73 version ready for download
Post Reply