Bài hôm nay mình sẽ hướng dẫn các bạn sử dụng một controll di chuyển khác trong andengien đó là MoveModifier
MoveXModifier
MoveYModifier
Video dướng dẫn : (like và G+ ủng hộ mình nha!)
Code : mainActivity.class
package com.example.movemonifer; import org.anddev.andengine.engine.Engine; import org.anddev.andengine.engine.camera.Camera; import org.anddev.andengine.engine.options.EngineOptions; import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation; import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; import org.anddev.andengine.entity.modifier.MoveYModifier; import org.anddev.andengine.entity.scene.Scene; import org.anddev.andengine.entity.scene.background.ColorBackground; import org.anddev.andengine.entity.sprite.Sprite; import org.anddev.andengine.entity.util.FPSLogger; import org.anddev.andengine.opengl.texture.Texture; import org.anddev.andengine.opengl.texture.TextureOptions; import org.anddev.andengine.opengl.texture.region.TextureRegion; import org.anddev.andengine.opengl.texture.region.TextureRegionFactory; import org.anddev.andengine.ui.activity.BaseGameActivity; public class MainActivity extends BaseGameActivity { private static final int CAMERA_WIDTH = 480; private static final int CAMERA_HEIGHT = 800; private Camera mCamera; private Texture textureAndengine; private TextureRegion textureRegionAndengine; @Override public Engine onLoadEngine() { this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera)); } @Override public void onLoadResources() { TextureRegionFactory.setAssetBasePath("gfx/"); this.textureAndengine = new Texture(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA); this.textureRegionAndengine= TextureRegionFactory.createFromAsset(this.textureAndengine, this, "logoimage.png", 0, 0); this.mEngine.getTextureManager().loadTexture(this.textureAndengine); } @Override public Scene onLoadScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f)); final Sprite sprite = new Sprite(10, 10, textureRegionAndengine); scene.attachChild(sprite); // MoveModifier modifier = new MoveModifier(4, sprite.getX(), CAMERA_WIDTH - sprite.getWidth() // , sprite.getY(), CAMERA_HEIGHT-sprite.getHeight()); // // sprite.registerEntityModifier(modifier); // MoveXModifier modifier = new MoveXModifier(5, sprite.getX(), CAMERA_WIDTH-sprite.getWidth()); // sprite.registerEntityModifier(modifier); MoveYModifier modifier = new MoveYModifier(5, sprite.getY(), CAMERA_HEIGHT-sprite.getHeight()); sprite.registerEntityModifier(modifier); return scene; } @Override public void onLoadComplete() { // TODO Auto-generated method stub } }
0 comments:
Post a Comment
http://knlaptrinhandroid.blogspot.com/