package com.PerleDevelopment.AndEngine.tutorial;import org.andengine.engine.camera.Camera;import org.andengine.engine.options.EngineOptions;import org.andengine.engine.options.ScreenOrientation;import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;import org.andengine.entity.scene.Scene;import org.andengine.entity.util.FPSLogger;import org.andengine.ui.activity.SimpleBaseGameActivity;public class AndEngineTutorialActivity extends SimpleBaseGameActivity { // =========================================================== // Constants // =========================================================== static final int CAMERA_WIDTH = 480; static final int CAMERA_HEIGHT = 800; // =========================================================== // Fields // =========================================================== private Camera mCamera; private Scene mMainScene; // =========================================================== // Constructors // =========================================================== // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override public EngineOptions onCreateEngineOptions() { this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera); } @Override protected void onCreateResources() { // TODO Auto-generated method stub } @Override protected Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); // logs the frame rate this.mMainScene = new Scene(); return this.mMainScene; }}Đầu tiên chúng ta tạo 1 Project Android đặt tên là AndEngineTutorial1 chẳng hạn và sau đó chúng ta đặt tên Activity là AndEngineTutorial1Activity chẳng hạn. Sau khi tạo Project thành công thì ta có lớp Activity. Chúng ta xóa hết thông tin bên trong lớp và kế thừa lớp SimpleBaseGameActivity như đoạn code trên. Sau đó chương trình yêu cầ bạn cài đặt method Abstract của super class. Bạn click vào lớp và Add unimplemented method --> Kết quả tạo ra 3 method như sau:
Tiếp theo chúng ta tạo ra 2 hằng CAMERA_WIDTH và CAMERA_HEIGHT. Nếu bạn biết chiều rộng và chiều cao của màn hình smartphone của bạn thì bạn khai báo. Trong bài sau tôi sẽ hướng dẫn các bạn lấy chiều cao và rộng của Smartphone.
Tiếp sau là chúng ta định nghĩa 2 biến đối tượng là Camera và Scene
Bây giờ chúng ta hãy nghiên cứu 3 method trong bài này:
- onCreateEngineOption()
+ Khởi tạo camera
- Camera(pX,pY,pWidth,pHeight)
- pX, Py là tọa độ của gốc tọa độ camera
- pWidth, pHeight là kich thước trong pixels của camera
+ Khởi tạo Energie
- EngineOption(pFullScreen, pScreenOrientation, pResolutionPolicy(pWidth, pHeight), pCamera)
- pFullScreen: Tùy chọn full screen hay không
- pScreenOrientation ở đây chúng ta có thể chọn LANPCAPE hoặc PORTAIR
- PRe....Là tỷ lệ của Engine của bạn
- Tham số cuối là đối tượng Camera
- onCreateResource(): Gọi để load tài nguyên
- onCreateScene():Gọi khi mọi thứ được cài đặt và texture được loaded
a ơi,e mới tìm hiểu android engine nên chưa biết nhiều... A có thể cho cho e xin mail of a được không? cám ơn a
Trả lờiXóa