Page 1 of 1
Collisions with rotated sprites
Posted: Mon Sep 14, 2015 1:38 am
by KeithTX
Is it possible to use SpriteCollision or SpritePixelCollision with a rotated sprite?
Thanks,
KeithTX
Re: Collisions with rotated sprites
Posted: Wed Sep 16, 2015 9:00 pm
by KeithTX
Okay, I'll assume that's a no then.
-Keith
Re: Collisions with rotated sprites
Posted: Wed Sep 16, 2015 10:38 pm
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
Re: Collisions with rotated sprites
Posted: Wed Sep 16, 2015 11:48 pm
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.

Re: Collisions with rotated sprites
Posted: Thu Sep 17, 2015 12:07 am
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.
Re: Collisions with rotated sprites
Posted: Fri Sep 18, 2015 9:00 pm
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
Re: Collisions with rotated sprites
Posted: Fri Sep 18, 2015 10:38 pm
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.
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 !
My sprite library does it *giggle*
Maybe you can ask for it in the requests forum
Re: Collisions with rotated sprites
Posted: Sat Sep 19, 2015 12:52 am
by KeithTX
DontTalkToMe wrote:KeithTX wrote:
I just knew it, yeeeeeeeeeeeeah, and without trying ! The power of the extrapolating hunch !
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
Re: Collisions with rotated sprites
Posted: Thu Sep 24, 2015 1:43 am
by juankprada
DontTalkToMe wrote:
My sprite library does it *giggle*
Is your sprite library available somewhere?
Re: Collisions with rotated sprites
Posted: Fri Oct 16, 2015 9:02 am
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
