Jump to content

"while being dragged" callback - how to?


wayfinder
 Share

Recommended Posts

perhaps I should clarify: I'm not looking for onDragStart and onDragStop events, i'm looking for something that does what I need to do every frame while the sprite is being dragged. So for example, if there was a way to put an update function in the sprite that would get called every frame, i could check in there whether the sprite is currently being dragged. or if there were an event that fired every frame and not just once on drag start. 

Link to comment
Share on other sites

yeah, i have an update function now that does get called (input provides an isDragged property so I don't have to set up the onDragStart/onDragStop callbacks). it's all not working yet for other reasons (i'm trying to access a variable that's in my state, but it is unexpectedly hard to do that from inside a sprite update call, and i feel like checking "this.game.state.states.Game.myVariable" is really ugly and possibly breaking something). edit: but it works for now, until something blows up and i have to re-do the entire thing again

 

edit 2: i think what's been throwing me off is that when I'm doing stuff in the Group, "this.game" refers to the state called "Game" (which I passed on creation as context), but inside the sprite I created in a function in the Group (via the GameObjectFactory), "this.game" points to the Phaser Game, i.e. states.Game.game. 

Link to comment
Share on other sites

edit 2: i think what's been throwing me off is that when I'm doing stuff in the Group, "this.game" refers to the state called "Game" (which I passed on creation as context), but inside the sprite I created in a function in the Group (via the GameObjectFactory), "this.game" points to the Phaser Game, i.e. states.Game.game. 

 

Group.game is a reference to the Phaser.Game instance, not the State. Unless you have specifically altered it otherwise.

 

Also: https://github.com/photonstorm/phaser/commit/2b0abb67ddaa7ecc5dcd59b568b94a0943db0c76

Link to comment
Share on other sites

Yeah, I wrote a new thing. That onDragUpdate though, awesome :)

 

The thing is, passing the state is/was very useful, since I have a state-level variable that tells me which of my Groups is currently in focus and stuff in the State is not otherwise readily available, except through the rather complicated route above. Is there a best practice for this kind of thing?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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