question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ct.mouse.hovers is triggered permanently instead of per-frame

See original GitHub issue

Describe the bug I have multiple copies and am trying to perform an action only for the specific copy the user clicks on. I do this check by using the following:

if (ct.actions.MYACTION.pressed && ct.mouse.hovers(this)) {
    // ...etc.
}

However, it looks like ct.mouse.hovers(this) returns true if your mouse has hovered over this copy at any point during the lifetime of the game.

To Reproduce Steps to reproduce the behavior:

  1. Create an action and set it to left mouse click.
  2. Create a Type using any texture you want.
  3. Place multiple copies of the Type into a Room.
  4. Paste the snippets of code shown below.
  5. Start the game in debug. Make sure you don’t hover over any copies to start.
  6. Pick any copy and click on it. Observe the console correctly printing position and integer.
  7. Then hover over another copy. Observe how not only did your current copy you clicked/hovered on change, but also the one you previously clicked, but are not hovering over anymore.

On Create:

this.current = 0;

On Step:

if (ct.actions.YOUR_ACTION.pressed && ct.mouse.hovers(this)){
    this.current++;
    console.log(this.position.x + "," + this.position.y + ": " + "this.currentState);
}

this.move();

Expected behavior I would have expected ct.mouse.hovers(this) to return true only if the mouse pointer is currently hovering over the current copy, false otherwise.

Screenshots (recommended) After clicking first square (X marks which square I clicked): Screen Shot 2020-12-30 at 2 43 42 PM

After clicking second square: Screen Shot 2020-12-30 at 2 45 05 PM

After clicking 3rd square: Screen Shot 2020-12-30 at 2 46 30 PM

Versions:

  • OS: macOS Catalina 10.15.7
  • ct.js version: 1.5.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dtgreenecommented, Dec 31, 2020

I downloaded it and checked. It’s because your collision mask is 512x512 but your sprites are 128x128. So they are overlapping each other causing you to click multiple at a time 😃

0reactions
mvxtcommented, Dec 31, 2020

🤦 Thank you for finding that. I don’t know when that was changed or how it got that way but thank you! I’ll close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mouseover and mouseout trigger multiple times - Stack Overflow
You can avoid this issue by using mouseenter instead of mouseover , and mouseleave instead of mouseout . The reason is simple: mouseenter...
Read more >
the of and to a in for is on s that by this with i you it not
... silver corporation wish inside solution mature role rather weeks addition ... lighting senate forces funny ct brother gene turned portable tried hawaii ......
Read more >
www.allitebooks.com - Pepa
mechanism is triggered to play a sound. in the same way, you can detect when a user hovers the mouse over a link...
Read more >
walmart air freshners
8-Pack Bamboo Charcoal Air Purifier Bag Natural Air Freshener Activated Carbon ... 19/ea Air Wick Plug in Scented Oil Refill, 5 ct, Lavender...
Read more >
Will Jenelle Evans Return to Teen Mom 2 Fans Think So her
... made several statements about permanently cutting ties with her. ... Evans (@j_evans1219) Why did Jenelle get fired from ' Teen Mom 2' ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found