2D: SpritePixelCollision with transparent Sprite

Advanced game related topics
PHP
User
User
Posts: 68
Joined: Sat Sep 10, 2005 5:38 pm

2D: SpritePixelCollision with transparent Sprite

Post 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
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: 2D: SpritePixelCollision with transparent Sprite

Post 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.
BERESHEIT
Post Reply