"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

(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"

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.