Skip to main content

Built on Android Game Application Use AndEngine

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


Comments

Popular posts from this blog

Mẹo và giải thuật C# dành cho người mới bắt đầu

Với nội dung kiến thức cơ bản nhất. Gồm 31 trang với những nội dung:  1. Kết nối CSDL SQL  -----------How to Create SQL Connection in C# 2. Đọc ghi file text với C#  -----------How to Write Text to a Txt File in C# -----------How to Read Text from a TXT File 3. Xóa Cookie C# -----------How to Delete Cookie Using C# 4. Gửi main sử dụng tài khoàn Gmail với C# -----------How to Send Email Using Your Gmail Account in C# 5. Kiểm tra ký tự nhập vào từ bàn  phím -----------How to Check If a Key Is Pressed In C# 6. Đổi tên file trong C# -----------How to Rename a File Using C# 7. Vô hiệu hóa chuột trong ô textbox C# -----------How to Disable Right Click in C# Textbox 8. Chọn tất cả trong listbox -----------How to Add Select All Button or Checkbox in CheckedListBox 9. Tạo mới thư mục bằng C# -----------How to Create a New Folder Using C# 10. Lấy các tiến trình đang chạy C# ----------- How to Get List of All the Running  Processes in C# 11. Tả...

Tài liệu hướng dẫn lập trình game với cocos2d-x

Thực hiện bởi: Admin Page Học Lập Trình https://www.facebook.com/hoclaptrinh.it Nội dung Phần 1: Cơ bản về cocos2d-x và khái niệm trong game Bài 1. Giới thiệu về Cocos2d-x Bài 2. Cài đặt Cocos2d-x Bài 3. Tạo ứng dụng đầu tiên Hello world Bài 4. Khái niệm Sprite và SpriteSheet Bài 5. Basic Action Bài 6. EFFECT & MUSIC Bài 7. Lập trình sự kiện Touch Bài 8. Cách tạo menu đơn giản (Cocos2d-x căn bản) Bài 9 . Hướng dẫn làm 1 game đơn giản bằng Cocos2d-x Phần 2: Vật lý trong game Bài 1 - Physics là gì, tại sao phải thêm Physics? ------------------------------Bắt đầu nội dung ------------------------------ “Write Once, Run Anywhere” (WORA)” Phần 1. Cơ bản về cocos2d-x và khái niệm trong game Bài 1. Giới thiệu về Cocos2d-x 1. Sơ lược về cocos2d-x 2. Vì sao chúng ta nên chọn cocos2d-x 3. Các kiến thức cần có 1. Sơ lược về cocos2d-x Là 1 Engine hỗ trợ lập trình Game đa nền tảng Xuất xứ từ trung quốc Hỗ trợ ngôn ngữ C+...

Bài tập thuật toán C/C++ Và Tuyển tập đề thi olympic

Gồm: +  Các thuật toán của Lê Minh Hoàng + Tuyển tập các đề thi olympic tin học sinh viên Link down: Tại đây