Hướng dẫn cài eclipse để làm game android năm 2024

Để bật các tính năng debug trong eclipse ta vào menu Window --> Show View: chọn Console, LogCat, nếu không tìm thấy vào Other.

this.mFontTexture \= new Texture[256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA];

this.mFont \= new Font[this.mFontTexture, Typeface.create[Typeface.DEFAULT, Typeface.BOLD], 32, true, Color.BLACK];

this.mEngine.getFontManager[].loadFont[this.mFont]; }

Viết code draw text ra màn hình:

//Phương thức hiển thị các đối tượng trong game

@Override

public Scene onLoadScene[] {

//...

//Draw text to screen

Text text = new Text[50, 50, mFont, "Welcome to iVietTech"];

scene.attachChild[text];

Log.i["FlappyBird", "Draw Text"];

return scene;

}

Bước 6: Vẽ background game Chuẩn bị đồ họa: tạo thư mục image trong thư mục assets ..\FlappyBird\assets\image, copy tất cả các tệp tin hình ảnh của game vào thư mục image. Đồ họa của game download ở đây, link: //drive.google.com/file/d/0B8tAQ0_sJKCSZmI1MTNIakhsN2s/view?usp=sharing

Khai báo biến load image background

//Image background

private TextureRegion mTextRegion_Background;

private Texture mTexture_Background;

Load hình background:

//Load các tệp tin tài nguyên: hình ảnh, âm thanh

@Override

public voidonLoadResources[] {

//Text

//Image background

TextureRegionFactory.setAssetBasePath["image/"];

this.mTexture_Background \= newTexture[512, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA];

this.mTextRegion_Background \= TextureRegionFactory.createFromAsset[this.mTexture_Background, this,"background.png", 0, 0];

this.mEngine.getTextureManager[].loadTexture[this.mTexture_Background];

}

Vẽ background ra màn hình:

//Phương thức hiển thị các đối tượng trong game

@Override

public Scene onLoadScene[] {

//...

//Draw background

Sprite sprite_Background \= new Sprite[0, 0, mTextRegion_Background];

scene.attachChild[sprite_Background];

//Draw text to screen

//...

return scene;

}

Bước 7: Vẽ background di động Khai báo biến load image background2

//Image background2

private TextureRegion mTextRegion_Background2;

private Texture mTexture_Background2;

private Sprite sprite_Background2;

Load hình background2:

//Load các tệp tin tài nguyên: hình ảnh, âm thanh

@Override

public void onLoadResources[] {

//Text

//Image background2

this.mTexture_Background2 \= new Texture[1024, 1024, TextureOptions.BILINEAR_PREMULTIPLYALPHA];

this.mTextRegion_Background2 \= TextureRegionFactory.createFromAsset[this.mTexture_Background2, this, "background2.png", 0, 0];

this.mEngine.getTextureManager[].loadTexture[this.mTexture_Background2];

}

Vẽ background2 ra màn hình:

//Phương thức hiển thị các đối tượng trong game

@Override

public Scene onLoadScene[] {

//...

//Draw background2

sprite_Background2\= new Sprite[0, 0, mTextRegion_Background2];

scene.attachChild[sprite_Background2];

//Draw text to screen

//...

return scene;

}

Build chạy thử xem đã load được background2 lên chưa! Tiếp theo để tạo hiệu ứng background2 động ta thay đổi tọa độ của background2

Chủ Đề