Page 1 of 1

2D: SpritePixelCollision with transparent Sprite

Posted: Fri Jul 16, 2010 5:18 pm
by PHP
Hi,

in wanna check if the crosshair is above a visible pixel of a sprite.

I load 2 sprites:

Code: Select all

CatchSprite(#Sprite_Crosshair,?Image2):DataSection:Image2:IncludeBinary "gfx\crosshair.bmp":EndDataSection
CatchSprite(#Sprite_Building,?Image6):DataSection:Image6:IncludeBinary "gfx\building.bmp":EndDataSection
I place the building (with some transparent windows) on the screen:

Code: Select all

DisplayTransparentSprite(#Sprite_Building,300,150)
Now i want to check the collision:

Code: Select all

If SpritePixelCollision(#Sprite_Crosshair,MouseX(),MouseY(),#Sprite_Building,MouseX(),MouseY()) And MouseButton(1)

; do something

EndIf
Are the parameters for the building correct? Because it's on a fixed place... or should i put there the values of it's position (300,150) in instead of the mouse positions?

Thanks,
PHP

Re: 2D: SpritePixelCollision with transparent Sprite

Posted: Fri Jul 16, 2010 5:31 pm
by netmaestro
You need to put the building position. Also, you may need to adjust your collision test coords for the mousepos to determine if the center of the crosshairs sprite is in collision with the building, as the top-left may not suffice.