Hi,
I was hoping someone might be able to help me with a 'newbie' question please.
I want to be able to move a mouse pointer around, and then when the mouse is clicked, record the x and y position and place a sprite in that position. The next time the mouse button is pressed, a second sprite is displayed at the new mouse position, and then finally, a third upon another mouse button click. Further mouse button clicks will then re-position the first sprite and so on......
This should leave 3 sprites on the screen, and record their positions.
The current code does this, and displays the x/y position of each sprite. The problem I have is that a single "mouse click" event is hard to make and the code loops round very quickly making discrete sprite positioning difficult.
Can anyone please suggest a way to remedy this?
Any help would be much appreciated.
Kind regards,
Paul :-)
Maybe don't record the click as a click until the mouse button goes back up? Like, while the mouse is being held down, show the sprite in the location of the mouse, but don't keep it there and increment to the next sprite number until the mouse buttons stops being pressed.
Here's another option:
function _update () if lclick==true then lclick=false end if band (stat (34),1)==1 then if lmb==false then lclick=true end lmb=true else lmb=false end if lclick then // placement code goes here end end |
Thanks very much for both of your suggestions.
I have played around a bit, bearing your ideas in mind and come up with the following code that does the job. Not elegant, but it works!!
Thanks again - much appreciated.
Paul :-)
a={}
a=1
function _init()
poke(0x5f2d, 1)
end
function _update()
mx=stat(32)
my=stat(33)
if mpress~=stat(34) and stat(34)~=0 then
a=a+1
end
mpress=stat(34)
function _draw()
cls()
spr(0,mx,my)
print(mpress,10,10)
print(a,10,20)
end
end
[Please log in to post a comment]