我有一個使用Android畫布創建的動態壁紙。經過測試,我覺得有必要利用OpenGL的力量,所以我正在試驗AndEngine。我想知道如何實現以下目標。AndEngine更新屏幕
我有填滿整個屏幕,與許多較小的位圖浮在上面(不是動畫運動)
到目前爲止,我有這樣的背景圖像的背景圖像:
@Override
public void onLoadResources()
{
mtexture = new Texture(1024, 1024, TextureOptions.BILINEAR);
TextureRegionFactory.setAssetBasePath("gfx/");
mtextureRegion = TextureRegionFactory.createFromResource(mtexture , this, R.drawable.background1, 0, 0);
this.mEngine.getTextureManager().loadTexture(this.mtexture);
}
@Override
public Scene onLoadScene(){
final Scene scene = new Scene(1);
Sprite background = new Sprite(0, 0, CAMERA_WIDTH*2, CAMERA_HEIGHT, mtextureRegion)
SpriteBackground sb = new SpriteBackground(background);
scene.setBackground(sb);
scene.setBackgroundEnabled(true);
return scene;
}
這適用於背景,但我需要移動精靈。
在我的畫布的代碼,我做了以下更新位置的移動物體的&物理和畫在畫布上每隔幾毫秒
private final Runnable drawScreen = new Runnable() {
public void run() {
drawFrame();
}};
-
void drawFrame() {
final SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
//draw
}
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
}
mHandler.removeCallbacks(drawScreen);
mHandler.postDelayed(drawScreen, 10);
}
什麼是適當的方式在AndEngine上做到這一點?我是否使用相同的代碼並替換openGL調用?
我看看GLEngine
,我應該發送Runnables到GlThread
隊列嗎?
編輯 - 我想我找到了答案...一個UpdateHandler。但是,我怎樣才能通知處理程序的更新(即調用onUpdate
方法)。如果我定時處理Handler,如果我經常打電話,會發生什麼情況,是否會建立一系列請求?