Vua Tên Miền chuyên cung cấp tên miền đẹp, giá rẻ! Hãy liên hệ kỹ thuật: 0914205579 - Kinh doanh: 0912191357 để được tư vấn, hướng dẫn miễn phí, Cảm ơn quý khách đã ủng hộ trong thời gian qua!
kinh doanh, bán hàng, tư vấn, bảo hiểm Những cá nhân, tổ chức, đại lý,muốn bán, hợp đồng bảo hiểm
Friday, July 18, 2014

Step 1: extends BaseGameActivity on AndEngine
PHP:
onLoadEngine
onLoadResources
onLoadScene
onLoadComplete
Step 2: Declaration variable
PHP:
    private static final int CAMERA_WIDTH 720;
    private static final 
int CAMERA_HEIGHT 480;

    private 
Camera mCamera;
    private 
BitmapTextureAtlas mBitmapTextureAtlas;
    private 
TiledTextureRegion mFaceTextureRegion;
Step 3: new variable on method
PHP:
public Engine onLoadEngine() {
        
// TODO Auto-generated method stub
        
this.mCamera = new Camera(00CAMERA_WIDTHCAMERA_HEIGHT);
        return new 
Engine(new EngineOptions(trueScreenOrientation.LANDSCAPE,
                new 
RatioResolutionPolicy(CAMERA_WIDTHCAMERA_HEIGHT),
                
this.mCamera));
    }
Step 4: Load Resources on Method onLoadResources
PHP:
@Override
    
public void onLoadResources() {
        
this.mBitmapTextureAtlas = new BitmapTextureAtlas(6432,
                
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
        
this.mFaceTextureRegion BitmapTextureAtlasTextureRegionFactory
                
.createTiledFromAsset(this.mBitmapTextureAtlasthis,
                        
"face_circle_tiled.png"0021);

        
this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas);
    }
Step 5: Load game on onLoadScene
PHP:
@Override
    
public Scene onLoadScene() {
        
// TODO Auto-generated method stub
        
this.mEngine.registerUpdateHandler(new FPSLogger());

        final 
Scene scene = new Scene();
        
scene.setBackground(new ColorBackground(0.09804f0.6274f0.8784f));

        final 
int centerX = (CAMERA_WIDTH this.mFaceTextureRegion.getWidth()) / 2;
        final 
int centerY = (CAMERA_HEIGHT this.mFaceTextureRegion
                
.getHeight()) / 2;
        final 
Ball ball = new Ball(centerXcenterYthis.mFaceTextureRegion);

        
Log.d("FishingonLoadScene",  "onLoadScene dx = " ball.getX()
                + 
"dy = " ball.getY());

        
scene.attachChild(ball);

        return 
scene;
    }
Insert class Ball:
PHP:
private static class Ball extends AnimatedSprite {
        private final 
PhysicsHandler mPhysicsHandler;

        public 
Ball(final float pX, final float pY,
                final 
TiledTextureRegion pTextureRegion) {
            
super(pXpYpTextureRegion);
            
this.mPhysicsHandler = new PhysicsHandler(this);
            
this.registerUpdateHandler(this.mPhysicsHandler);
            
mPhysicsHandler.setVelocity(DEMO_VELOCITYDEMO_VELOCITY);
        }

        @
Override
        
protected void onManagedUpdate(final float pSecondsElapsed) {
            if (
this.mX 0) {
                
this.mPhysicsHandler.setVelocityX(DEMO_VELOCITY);
            } else if (
this.mX this.getWidth() > CAMERA_WIDTH) {
                
this.mPhysicsHandler.setVelocityX(-DEMO_VELOCITY);
            }

            if (
this.mY 0) {
                
this.mPhysicsHandler.setVelocityY(DEMO_VELOCITY);
            } else if (
this.mY this.getHeight() > CAMERA_HEIGHT) {
                
this.mPhysicsHandler.setVelocityY(-DEMO_VELOCITY);
            }
            
Log.d("FishingonManagedUpdate""onManagedUpdate dx = " this.getX() + "dy = "
                    
this.getY());
            
super.onManagedUpdate(pSecondsElapsed);
        }
    }
Notes library on using project:
PHP:
package studycoding.net.movingball;
import org.anddev.andengine.engine.Engine;import org.anddev.andengine.engine.camera.Camera;import org.anddev.andengine.engine.handler.physics.PhysicsHandler;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.scene.Scene;import org.anddev.andengine.entity.scene.background.ColorBackground;import org.anddev.andengine.entity.sprite.AnimatedSprite;import org.anddev.andengine.entity.util.FPSLogger;import org.anddev.andengine.opengl.texture.TextureOptions;import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;import org.anddev.andengine.ui.activity.BaseGameActivity;
import android.util.Log;

  Step 6: Buil applition: 
Xây Dựng Ứng Dụng Game trên Android Sử dụng AndEngine


0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts