Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Detecting which sprite is being clicked

Author
Message
Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 28th Aug 2011 16:33
Hey,
I've been trying to figure this out for ages, but it seems impossible

I need a way of detecting whether a sprite is being clicked, and if it is, I need to know which sprite is being clicked... I've been trying for a few days now, but I cant figure it out

Any help will be much appreciated

Matt

Umm...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 28th Aug 2011 18:51
Two ways spring instantly to mind...

1) Use a sprite for the mouse pointer and check collision with that against all the other sprites on screen.

2) Check to see if the Mouse co'ords fall inside sprite x,Sprite y and sprite x + sprite width, sprite y+sprite height.

Hope that helps.

pcRaider
17
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 28th Aug 2011 18:51
Try this

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Aug 2011 19:25
The easiest way is like =PRoF='s first thought and like pcRaiders code but with the SPRITE COLLISION command if you have a target number of zero it'll return the sprite number that it's colliding with.

I have to go real quick so I modified pcRaiders code:


Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 28th Aug 2011 20:00
thanks so much for this guys

Welcome down to London City where the attitudes bad and the weather is shitty...
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 29th Aug 2011 18:31
I liked very much this idea. When I have a lots of items dropped on the floor , is it possible to pickup the item of specific sprite?
The problem is , my items are not sprites are images.
I have to make a lots of changes in my code.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 30th Aug 2011 04:01
Yes, because SPRITE COLLISION returns the sprite number (if you use a target sprite number of zero) you can use that to "pick up" the specific sprite from the screen.

Same code above modified to "pick up" a sprite with the mouse button:


Login to post a reply

Server time is: 2024-11-24 01:16:45
Your offset time is: 2024-11-24 01:16:45