how to detect sprite is moving or not

  ... the case you feel the need for a new feature or want to submit one.

how to detect sprite is moving or not

Postby najhi » Wed Apr 11, 2012 9:23 pm

Hello
Is there any way built in in andEngine to detect a shape or sprite is moving or not. Actually i am designing a snooker game and i want to allow user to touch que ball only when no ball is moving.

Thanks in Advance :)
najhi
 
Posts: 13
Joined: Sat Mar 31, 2012 9:36 am

Re: how to detect sprite is moving or not

Postby badchoice » Tue Apr 17, 2012 2:01 pm

Very easy, you just need to override the onManagedUpdate of the sprite and do something like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void onManagedUpdate(pSecondsElapsed){
  2.      if(this.getX() != previousX || this.getY() != previousY) isMoving = true;
  3.      else                                                     isMoving = false;
  4.  
  5.      previousX = this.getX()
  6.      previousY = this.getY()
  7.  
  8. }
  9.  
  10. public boolean isMoving(){
  11.     return isMoving;
  12. }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
badchoice
 
Posts: 91
Joined: Wed Apr 06, 2011 9:23 am
Location: Barcelona

Re: how to detect sprite is moving or not

Postby OzLark » Tue Apr 17, 2012 3:28 pm

That a good solution badchoice, but I'm thinking it might not work in all cases? Is it a given that all location changing modifiers (with what ever ease function is specified) will modify the location on EVERY update? If it is, then great, otherwise this might give some unpredictable results - Just thinking out aloud here :)
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
OzLark
 
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: how to detect sprite is moving or not

Postby badchoice » Tue Apr 17, 2012 5:30 pm

Well, in slow motions it will not change,
another thing you can do if you move it using modifiers, is getting the list of registred modifiers for that item, and check if there is a move modifier, and if there is, check if it ended and is active

if you allways move it using modifiers, then just do this modifiers thing
badchoice
 
Posts: 91
Joined: Wed Apr 06, 2011 9:23 am
Location: Barcelona

Re: how to detect sprite is moving or not

Postby najhi » Tue Jun 05, 2012 9:31 am

Thank you so much it worked for me :)
najhi
 
Posts: 13
Joined: Sat Mar 31, 2012 9:36 am


Return to Features

Who is online

Users browsing this forum: No registered users and 5 guests