Rendercam + Defold-input => weird cursor position when scrolling

Hi guys!

I’m currently working on an idle game prototype. I’ve used:

1/ Defold-input to be able to interact with game objects @britzl
2/ Rendercam for the camera basics @ross.grams

Both work exactly as intended separately, but when I mix them… something weird happens:

As you can see, at the beginning I move the cursor over the buildings (that are highlighted) and then click them to upgrade. But when I scroll, the buildings move but not their “screen position” (?). I have to click below their displayed position to upgrade them :frowning:

Probably something related to world pos, screen pos, or something… but I don’t know what exactly :see_no_evil:

Can someone help me? :sweat_smile:

Can you please enable Physics Debug and check where the collision objects are?

@britzl
The collision boxes seem to follow the objects:

edit: do you need a minimal version of the project to understand what’s wrong?

There must be something wrong with the screen to world translation from render cam and how you pass that on to the mouse cursor. Like I do in this example using Orthographic:

@britzl thank you for this example! I’ve used it yesterday in my project and it works as intended :slight_smile:

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)

The solution you have where your position the cursor every frame is probably the only way I can think of myself.

Sounds strange. I need to look into this to better understand the problem. Can you create an issue on GitHub please?

This is something the cursor script should support. Please create a ticket in GitHub!

1 Like

Just to be sure, I have to create 2 different tickets on GitHub?

(same minimal project + same extensions, but maybe 2 different problems)

In general, it’s recommended to create one ticket per issue.

There are exceptions ofc. E.g. if the issues are very intimately related, so they can be considered the “same” issue.

3 Likes

Ok I think I’ll create 2 different issues, because one is more like a feature request/completion (cursor teleport when clicking, for mobile games), and the other a possible bug (real-time following creating “conflicts” between action_ids).

Just finished preparing the minimal version of the project so it’ll be easier to investigate.

2 Likes