Jump to content

mouse events on newly generated sprites


wayfinder
 Share

Recommended Posts

Hi!

 

In my game, I have a button. When I click it, the button is moved out of the way and I create a new sprite at the mouse pointer's position. The problem is: the new sprite doesn't seem to register pointer events correctly. I realize that when I create a new sprite under the pointer, there won't be an onInputOver or onInputDown event, but when I move the mouse and let go of the mouse button, I'm getting neither onInputOut nor onInputUp, and those should definitely be there. I've also added a moveCallback to the sprite, which doesn't fire.

 

All the events fire correctly after I have moved the pointer away from the sprite once.

 

Is there a way to fix this?

Link to comment
Share on other sites

I'm not quite clear on what you're doing. Is this it?

 

1. Hover over a button.

2. Press the mouse button down.

3. The button disappears and is replaced (?) with a sprite.

4a. Move mouse and see that there is no onInputOver event?

5. Let mouse button go.

6a. Click mouse button and there's no onInputDown?

 

When you say the button is moved out of the way, is it killed or just set to an offscreen position?

Link to comment
Share on other sites

1. Hover over a button

2. Press mouse button down

3. the onInputDown event for the button moves it somewhere offscreen (it's not destroyed) and creates a new sprite under the cursor

4. move mouse and the new sprite's mouseMove callback doesn' fire

5. let mouse button go, the new sprite doesn't register an onInputUp event

6. move mouse out from the sprite and its onInputOut doesn't fire

Link to comment
Share on other sites

Okay, cool, that's kinda what I thought.

 

I'm betting your input manager is holding on to its previous target object and, since it's visible and active, keeping it as the current object while the mouse is down because it might be being dragged.

 

I'm not sure what's going to fix it. First I'd try iterating through all the "game.input.pointer#" members and setting them dirty, i.e. "game.input.pointer1.dirty = true;". That *should* get them to update whether or not they've moved or not and re-check what they're hovering over.

 

If that doesn't work we drift into the land of hackery. Setting the button "visible = false;"? Setting one of its scales to 0 on the button, e.g. "sprite.scale.x = 0;"? 

Link to comment
Share on other sites

I can't really mess with the button, it's supposed to be still functional, just in a different place :/ I tried the dirty flag, the pointer's update function (no dice on either), and manually setting the targetObject (which produced an exception when there was no _pointerOutHandler set). 

 

I did manage to solve my problem in a way, although it certainly feels hacky as all get out: In the sprite's mouseMove callback, I check the pointer's isUp property and whether I'm currently dragging the sprite. If both are true, I manually trigger the onMouseUp function of the sprite. This seems to work to stop dragging the new sprite when I let go of the mouse. I've changed the behavior of the sprite so that the onMouseOut doesn't need to be triggered so that's squashed as well... as for why the mouseMove callback now works and previously didn't, I have no idea. The whole pointer thing seems to do what it wants sometimes (had to re-start the browser a few times when it stopped registering ANY clicks on my objects)

 

 

Thanks for your help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...