wayfinder Posted June 27, 2015 Share Posted June 27, 2015 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 More sharing options...
wayfinder Posted June 28, 2015 Author Share Posted June 28, 2015 Has anybody had experience with this sort of thing? Is there a way to tell the pointer it's currently over a certain sprite and it's being clicked and dragged, so that it will fire mouseMove callbacks and onInputUp/onInputOut events? Link to comment Share on other sites More sharing options...
wayfinder Posted June 29, 2015 Author Share Posted June 29, 2015 Is it possible to create a sprite in the state of being clicked perhaps? Do you know? Link to comment Share on other sites More sharing options...
drhayes Posted June 29, 2015 Share Posted June 29, 2015 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 More sharing options...
wayfinder Posted June 29, 2015 Author Share Posted June 29, 2015 1. Hover over a button2. Press mouse button down3. the onInputDown event for the button moves it somewhere offscreen (it's not destroyed) and creates a new sprite under the cursor4. move mouse and the new sprite's mouseMove callback doesn' fire5. let mouse button go, the new sprite doesn't register an onInputUp event6. move mouse out from the sprite and its onInputOut doesn't fire Link to comment Share on other sites More sharing options...
drhayes Posted June 30, 2015 Share Posted June 30, 2015 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 More sharing options...
wayfinder Posted June 30, 2015 Author Share Posted June 30, 2015 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 More sharing options...
Recommended Posts