1. Location: Modifier_example---MovingBall2. Class Name: Movingball
(1). Sprite movement We can update the sprite's X, y position to achieve the moving effect each time we refresh, below we use Physicshandler event to move a smiley spirit, by changing the X-physicshandler event, y rate makes the sprite move.
/**
* define a ball wizard
* @author lin
*
*/
private static class ball extends animatedsprite {
/* * Mobile Processing Event */
private final physicshandler mphysicshandler;// A iupdatehandler logical transaction
 &NBSP that automatically updates the entity location;
public ball (final float px, final float py, string ptextureregion, final vertexbufferobjectmanager Pvertexbufferobjectmanager) {
super (px, py, ptextureregion, Pvertexbufferobjectmanager);
this.mphysicshandler = new physicshandler (this);//instantiation of Events
this.registerupdatehandler (This.mphysicshandler);//Register the event before it is executed
This.mPhysicsHandler.setVelocity (demo_velocity, demo_velocity);//Set x, y rate
}
//Control Wizard always moves inside the screen, not outside the screen
@Override
protected void Onmanagedupdate (final float psecondselapsed) {
if (this.mX < 0 ) {//ball elf x coordinate is less than 0 o'clock
this.mphysicshandler.setvelocityx (demo_velocity);// Set the x rate to positive, that is, move to the right
} else if (This.mx + this.getwidth () >= scene_width) {//ball Wizard x coordinates are larger than the right side of the screen, i.e. move out of the screen to the right
This.mPhysicsHandler.setVelocityX (-demo_velocity);//set X rate to negative, i.e. move to left
}
if (this.my < 0) {//ball elf y-coordinate is less than 0 o'clock
This.mPhysicsHandler.setVelocityY (demo_velocity);//set Y rate to positive, i.e. move down
} else if (this.my + this.getheight () >= scene_height) {//ball Wizard y-coordinate is larger than the bottom of the screen
This.mPhysicsHandler.setVelocityY (-demo_velocity);//set Y rate to negative, i.e. move upward
}
Super.onmanagedupdate (psecondselapsed);//method that executes the parent class
}
}
Oge_example Project Source Code
"V2.x Oge-example chapter II (first section) the movement of the Elves"