wayfinder Posted June 4, 2015 Share Posted June 4, 2015 I'm creating sprites that will be draggable, and i'd like to perform certain tasks while they're being dragged. Is there a painless way to do this? Link to comment Share on other sites More sharing options...
wayfinder Posted June 4, 2015 Author Share Posted June 4, 2015 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 More sharing options...
wayfinder Posted June 4, 2015 Author Share Posted June 4, 2015 AND perhaps i should also say that the first thing i tried was setting up a prototype.update function but that never gets called. Link to comment Share on other sites More sharing options...
jaevelgames Posted June 4, 2015 Share Posted June 4, 2015 Cant you set a Var like dragging = true on onDragstart, and false on onDragStop.And use if( dragging ){ 'blablabla* } in your update function? in mono 1 Link to comment Share on other sites More sharing options...
wayfinder Posted June 4, 2015 Author Share Posted June 4, 2015 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 More sharing options...
rich Posted June 4, 2015 Share Posted June 4, 2015 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 drhayes 1 Link to comment Share on other sites More sharing options...
wayfinder Posted June 4, 2015 Author Share Posted June 4, 2015 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 More sharing options...
Recommended Posts