Andengine processes the 4-way walking diagram of the 12 Ge

Source: Internet
Author: User

For other types of walking charts, such as the 16 Gangu or the 8 direction, the operation method is similar. You can also refer to this article.

The following is the two images I use. player.png on the left is the next.png on the right of the picture as a picture of the top, bottom, and left buttons.

Code:

Public class mainactivity extends simplebasegameactivity {Private Static final int camera_width = 800; Private Static final int camera_height = 480; private encrypted rows; private bitmaptextureatlas marrowtextureatlas; private textureregion rows; public engineoptions oncreateengineoptions () {final camera = new camera (0, 0, camera_width, camera_height); return New engineoptions (true, screenorientation. landscape_fixed, new ratioresolutionpolicy (camera_width, camera_height), camera) ;}@ overrideprotected void oncreateresources () {bitmaptextureatlastextureregionfactory. setassetbasepath ("GFX/"); this. mbitmaptextureatlas = new bitmaptextureatlas (this. gettexturemanagers (), 128,128); this. mplayertextureregion = bitmaptextureatlastextureregionfactory. createtiledfromasset (this. mbitmaptextureatlas, this, "player.png", 0, 0, 3, 4); this. mbitmaptextureatlas. load (); this. marrowtextureatlas = new bitmaptextureatlas (this. gettexturemanagers (), 128,128); this. marrowtextureregion = bitmaptextureatlastextureregionfactory. createfromasset (this. marrowtextureatlas, this, "next.png", 0, 0); this. marrowtextureatlas. load () ;}@ overrideprotected scene oncreatescene () {final scene = new scene (); Final animatedsprite player = new animatedsprite (100,100, 48, 64, this. mplayertextureregion, this. getvertexbufferobjectmanager (); scene. attachchild (player); Final sprite up = new sprite (72,480-120, this. marrowtextureregion, this. getvertexbufferobjectmanager () {// rewrite the sprite touch event @ overridepublic Boolean onareatouched (touchevent pscenetouchevent, float ptoucharealocalx, float ptoucharealocaly) {// read the index from the sprite animation from the 0 to 2 frames for repeated playback, each frame lasts for 200 ms player. animate (New long [] {200,200,200}, 0, 2, true); Return true ;}}; up. setrotation (270); // rotate the arrow image 279 degrees as the up button. setscale (0.5f); // The image size is relatively large, which is reduced by half. Final sprite down = new sprite (72,480-72, this. marrowtextureregion, this. getvertexbufferobjectmanager () {@ overridepublic Boolean onareatouched (touchevent pscenetouchevent, float ptoucharealocalx, float ptoucharealocaly) {player. animate (New long [] {200,200,200}, 6, 8, true); Return true ;}}; down. setrotation (90); down. setscale (0.5f); Final sprite left = new sprite (24,480-72, this. marrowtextureregion, this. getvertexbufferobjectmanager () {@ overridepublic Boolean onareatouched (touchevent pscenetouchevent, float ptoucharealocalx, float ptoucharealocaly) {player. animate (New long [] {200,200,200}, 9, 11, true); Return true ;}}; left. setrotation (180); left. setscale (0.5f); Final sprite right = new sprite (120,480-72, this. marrowtextureregion, this. getvertexbufferobjectmanager () {@ overridepublic Boolean onareatouched (touchevent pscenetouchevent, float ptoucharealocalx, float ptoucharealocaly) {player. animate (New long [] {200,200,200}, 3, 5, true); Return true ;}}; right. setscale (0.5f); // Add the direction keys to the scene. attachchild (up); scene. attachchild (down); scene. attachchild (left); scene. attachchild (right); // register the sprite's touch event scene. registertoucharea (up); scene. registertoucharea (down); scene. registertoucharea (left); scene. registertoucharea (right); // The touch mode scene of the binding scenario. settouchareabindingonactiondownenabled (true); Return scene ;}}

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.