Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Link: http://vietandroid.com/threads/bai-1-ve-1-hinh-don-gian-len-man-hinh-e3droid.6856/
- package Bai_1_e3droid.gioi;
- import android.view.MotionEvent;
- import com.e3roid.E3Activity;
- import com.e3roid.E3Engine;
- import com.e3roid.E3Scene;
- import com.e3roid.drawable.Shape;
- public class Bai_1_e3droidActivity extends E3Activity {
- private final static int WIDTH = 320;//Chiều rộng của màn hình
- private final static int HEIGHT = 480;//Chiều cao của màn hình
- private final static int BOX_SIZE = 50;//Kích thước của 1 box
- private Shape shape1, shape2, shape3, shape4;//Khai báo 4 biến shape
- @Override
- public E3Engine onLoadEngine() {
- E3Engine engine = new E3Engine(this, WIDTH, HEIGHT);//Thiết lập chiều cao và rộng
- engine.requestFullScreen();//Set màn hình full
- engine.requestPortrait();
- return engine;
- }
- @Override
- public E3Scene onLoadScene() {
- E3Scene scene = new E3Scene();
- scene.addEventListener(this);//Bắt sự kiện khi bạn chạm lên màn hình
- //Khỏi tạo màu cho các hình. (Các bạn thử thay đổi các giá trị xem sao nhé)
- shape1.setColor(1, 0, 0, 1);
- shape2.setColor(0, 1, 0, 1);
- shape3.setColor(0, 0, 1, 1);
- shape4.setColor(1, 1, 0, 1);
- //Hiện thị các hình này lên. Chú ý: nếu không add mấy cái shape vào thì sẽ không bao giờ nhìn thấy trên
- //màn hình
- scene.getTopLayer().add(shape1);
- scene.getTopLayer().add(shape2);
- scene.getTopLayer().add(shape3);
- scene.getTopLayer().add(shape4);
- return scene;
- }
- @Override
- public void onLoadResources() {
- int centerX = getWidth() / 2;//Xác định ví trí trung tâm theo tọa độ X
- int centerY = getHeight() / 2;//Xác định ví trí trung tâm theo tọa độ Y
- //Khởi tạo vị trí cho các hình này khi hiện thị lên màn hình
- shape1 = new Shape(centerX, centerY, BOX_SIZE, BOX_SIZE);
- shape2 = new Shape(centerX-BOX_SIZE, centerY-BOX_SIZE, BOX_SIZE, BOX_SIZE);
- shape3 = new Shape(centerX-BOX_SIZE, centerY, BOX_SIZE, BOX_SIZE);
- shape4 = new Shape(centerX, centerY-BOX_SIZE, BOX_SIZE, BOX_SIZE);
- }
- @Override
- public boolean onSceneTouchEvent(E3Scene scene, MotionEvent motionEvent) {
- // shape1(red box) rotates and scales when touchEvent ACTION_DOWN occurs.
- if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
- //Thực hiện xoay hình shape1 và phóng to khi bạn chạm vào màn hình
- shape1.rotate(shape1.getAngle() + 20.0f, BOX_SIZE/2, BOX_SIZE/2);
- shape1.scale(shape1.getScaleX() + 0.2f, shape1.getScaleY() + 0.2f, BOX_SIZE / 2, BOX_SIZE / 2);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment