Page 1 of 1

which function to find the id of the sprite or brush click t

Posted: Wed May 20, 2015 3:08 pm
by sinisrus
Hello,

which function to find the id of the sprite or brush if click with mouse?

thank you

Re: which function to find the id of the sprite or brush cli

Posted: Wed May 20, 2015 4:29 pm
by Bugala
If i udnerstand your question right, then it is not that simple.

What you are probably after, is that you would first make them into a button.

When making that button you could use "userdata" option, and put layer id on that.

That way on button pressed function you could simply use:

layername = msg.userdata


Another way that you could try is to save mousex and mousey co-ordinates of the current location when mouse is clicked.

After that you would make rectangle collision check of each layer, the layer that is colliding with the area, must be under the mouse pointer then. This of course supposing each layer is separate from each other, since if there are multiple layers under mouse pointer at same time, then each would return true for collision check.

Hope this helped something. Felt too tired making actual code examples this time.

Re: which function to find the id of the sprite or brush cli

Posted: Thu May 21, 2015 1:34 am
by zylesea
You don't need a button. You always know all positions of your sprites (actually they do have precise coordinates) and you know the position of your mouse by MouseX() and MouseY(). Now you only need to check whether your actual pointer coordinate is within the coordinates of one or several sprite (some loop). Collision detection of a sprite against an X/Y coordinate is to my understanding not possiblem hence the need of checking yourself. Or create a certain 1px helper sprite that gets displayed at the actual mouse coordinates and use collision(#sprite, id1,id2) to check for collision. of course yo need to check every sprite against that mouse pointer coordinate sprite.
Something like that. Of course yo need the actual number of sprites in use. Something like that (just quickly written down, no actual tested code)

Code: Select all

If IsRightMouse() = True
sposX$=MouseX()  
sposY$=MouseY()  
displaysprite(1000,sposX$,sposY$) ;show your "mousesprite"
for i=1 to YourNumberOfSprites$
if collision(#sprite, id1,id2) =true then debugprint("Sprite no.", YourNumberOfSprites$,"is under the mousepointer")
displaysprite(1000,-1,-1) ;remove your mousesprite
next
endif

Re: which function to find the id of the sprite or brush cli

Posted: Thu May 21, 2015 10:30 am
by sinisrus
@zylesea, Bugala

thank you, I find function for return id of sprite if I put the mouse over the Sprite