Log In  
Log In  

Cart [#42682#] | Code | 2017-07-21 | License: CC4-BY-NC-SA | Embed

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 :-)

P#42683 2017-07-21 15:57 ( Edited 2017-07-25 11:50)

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.

P#42684 2017-07-21 16:14 ( Edited 2017-07-21 20:14)
:: enargy

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
P#42690 2017-07-21 16:57 ( Edited 2017-07-21 20:57)

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

P#42770 2017-07-25 07:50 ( Edited 2017-07-25 11:50)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-05-26 23:08 | 0.029s | 4194k | Q:26