java - A variable that holds coordinates of last mouse click only -


this i'm trying accomplish. want item show on screen @ last position mouse had clicked. sort of works, every time click elsewhere said item moves there well. want static.

here's code:

global variables px , py. used hold mouse clicks:

private int px = 250; // initial coordinates private int py = 250; 

mouse clicks feed global px , py:

private void testpress(int x, int y) {     if (!ispaused && !gameover) {         // something..         px = x;         py = y;         girlp.setdestination((px-(girlp.getimage().getwidth(this)/2)),                  (py-(girlp.getimage().getheight(this)/2)));          //system.out.println(px + ", " + py);     } } 

there px , py updated new values. want way hold last mouse click

see this question understand how listen mouse events

you can use event.clickx , event.clicky coordinates within element listen mouse click on, or use event.screenx , event.screeny absolute mouse coordinates within document.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -