"V2.x Oge-example chapter II (first section) the movement of the Elves"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.