@britzl thank you for this example! I’ve used it yesterday in my project and it works as intended
For now, the lines in question are the “input” function and the cursor follows the input position as intended, but there are 2 specific cases I’ve been struggling with:
1/ Real-time following… when not moving the mouse
When I don’t move the mouse, the cursor stops following -which is pretty normal since the message is passed from the input function (so when I scroll then stops moving the mouse, this mouse remains at the same position but the cursor follows the camera movement - and then they re-synchronize when I mouse the mouse again)
How to make the cursor follow in real-time the input position? (in a “clean”/bugfree manner)
For now I’ve added the message passing (to the cursor) in the update loop
function update(self, dt)
local mouse_pos_cur_WORLD = rc.screen_to_world_2d(self.mouse_pos_cur.x, self.mouse_pos_cur.y)
self.action.x = mouse_pos_cur_WORLD.x
self.action.y = mouse_pos_cur_WORLD.y
msg.post("cursor#cursor", "input", { action_id = self.action_id, action = self.action })
end
I seemed to work fine in the basic test scene (see my “about to be deleted” message)… but I realized that in the building game prototype, it seems to … create some sort of “conflicts” with the other cursor’s action_id… For example, the “release” is no longer detected when I actually release but only when I move after having released (I don’t know how to explain it better, so I made another short video). And the buildings are upgraded consequently (only when I move after having released it). For some reasons, I need to move the mouse so the release can be detected…
2/ Cursor instantly repositioned when clicking
Since I want my prototype to become a mobile game, I need the cursor to “teleport” to the mouse position when I click/tap (to be able to interact with my buildings without having to drag the cursor before - since there is no cursor dragging on mobile)
When I pass the position to the cursor directly from the action.pressed “touch”, the click seems to be detected but the cursor doesn’t teleport to the input position… :-/
Again, is there a clean way to “teleport” the cursor when clicking?
(so players (on mobile) can tap buildings anywhere on the screen to upgrade them)
General note : I’m sorry for posting long messages, and I try to avoid asking questions/for help too frequently… but when I do it’s because I’m really stuck with something important for my project. I don’t know if I should keep it super short (a few words describing the problem) or detailed (in my previous messages I tried to provide everything I can, quick descriptions of my tries/mistakes, screenshots, videos, sometimes minimal project etc. to make it easier for people who can help but maybe I’m wrong => cf the “about to be deleted” message) => should I keep providing as many info as I can in that kind of situations? (not a problem for me, but maybe a bit too “heavy” for readers… I don’t know - my only objective is to find solutions to my problems)