1. Location: Modifier_example- Movingball2. Class Name: Movingball
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/4D/DD/wKioL1RbPfCQs6jDAABPpPvO-j0861.jpg "title=" Chapter II the first section. png "alt=" wkiol1rbpfcqs6jdaabpppvo-j0861.jpg " />
(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 elf
* @author Lin
*
*/
private static Class ball extends Animatedsprite {
/** Mobile Processing Events * /
Private Final Physicshandler mphysicshandler;//a iupdatehandler logical transaction that automatically updates the entity location
Public Ball (final float PX, final float PY, String ptextureregion, final Vertexbufferobjectmanager Pvertexbufferobje Ctmanager) {
Super (PX, PY, Ptextureregion, Pvertexbufferobjectmanager);
This.mphysicshandler = new Physicshandler (this);//instantiation of Events
This.registerupdatehandler (This.mphysicshandler);//Registration of events, registration will not be executed
this.mPhysicsHandler.setVelocity (demo_velocity, demo_velocity);//set X, y rate
}
//Control wizard will always move 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 X rate to positive, i.e. move to right
} else if (this.mx + this.getwidth () >= scene_width) {//ball elf x coordinates are larger than the right side of the screen, move out of the screen to the right
This.mPhysicsHandler.setVelocityX (-demo_velocity);//set X rate to negative, i.e. move left
&NBSP;&NBSP;&NBSP;}
if ( this.my < 0) {//ball elf y coordinates 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 greater than the bottom of the screen
&NBSP;&NBSP;&NBSP;}
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"