I’m making a game where the player can move a crosshair around the screen with a mouse click or touch. The idea is to fire a shot at the object under the cursor when the mouse click or touch is released.
I’ve found that if you start a touch at a random position in space, and then drag your finger over an object and release the touch, nothing happens. cursor.RELEASED only works if your touch starts and ends on the object without leaving the object’s bounds. This also happens in the cursor example given on defold-input’s GitHub page.
Am I misunderstanding how the cursor works, or should I be taking a different approach?
No, that is how it is designed to work. When I created the cursor logic I didn’t consider your use-case. The cursor can handle what I would consider normal UI interaction:
Moving the cursor over and out of an object
Press on an object
Drag an object
Clicking on an object (press+release inside the object)
Pressing outside, then moving over an object and releasing is not something I considered. If I were to add support for this I’m worried that it may have side-effects in other use cases which I haven’t considered.
That’s fine, I think for this use case I would want to use native on_input events and check if the touch position is inside some arbitrary rectangle around that object’s position. Either by getting the sprite’s size, or by creating points in code.
Was just hoping defold-input would let me sidestep all that, but I think this solution is fine.