gpt4 book ai didi

android - 使用 An Engine Live Wallpaper 扩展启动动画

转载 作者:搜寻专家 更新时间:2023-11-01 07:37:29 25 4
gpt4 key购买 nike

我有这样的代码:

public class SnowFallService extends BaseLiveWallpaperService implements IOnAreaTouchListener{

// ===========================================================
// Constants
// ===========================================================

private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 800;

private ArrayList<Sprite> allSnow = new ArrayList<Sprite>();
// ===========================================================
// Fields
// ===========================================================

private ScreenOrientation screenOrientation;

private static TextureRegion snowTexture;
private static TextureRegion backgroundTexture;
private static Textures texture = null;

private Scene mScene;

public org.anddev.andengine.engine.Engine onLoadEngine() {
return new org.anddev.andengine.engine.Engine(new EngineOptions(true, this.screenOrientation, new FillResolutionPolicy(), new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT)));
}

public void onLoadResources() {
texture = new Textures(this, getEngine());
}

public void onUnloadResources() {

}

public Scene onLoadScene() {

final Scene mScene = new Scene();
backgroundTexture = texture.getBackground();
mScene.attachChild(new Sprite(0, 0, backgroundTexture));
snowTexture = texture.getSnowTextureRegion();

mScene.registerUpdateHandler(new IUpdateHandler() {
private long lastRaindropAdd = 0;

@Override
public void onUpdate(final float pSecondsElapsed) {
int size = allSnow.size();
int tmpInt = 0;
Random randGen = new Random();
for (int i = 0; i < size; i++) {
if (allSnow.get(i) != null){
Sprite snow = allSnow.get(i);

tmpInt = randGen.nextInt(4);
snow.setPosition(snow.getX() + (randGen.nextInt(5) - randGen.nextInt(5)) * randGen.nextInt(3), snow.getY() + tmpInt);

if (snow.getY() > CAMERA_HEIGHT || snow.getX() > CAMERA_WIDTH) {
synchronized(snow) {
size--;
allSnow.remove(i);
mScene.detachChild(snow);
}
}
}
}

tmpInt = randGen.nextInt(5000);

if (System.currentTimeMillis() - lastRaindropAdd > tmpInt) {
lastRaindropAdd = System.currentTimeMillis();

tmpInt = randGen.nextInt(CAMERA_WIDTH);

Sprite snow = getRaindrop(tmpInt, 0);
allSnow.add(snow);
mScene.attachChild(snow);
}
}

@Override
public void reset() {
}
});
return mScene;
}

public void onLoadComplete() {
// TODO Auto-generated method stub

}

public void onPauseGame() {
// TODO Auto-generated method stub

}

public void onResumeGame() {
// TODO Auto-generated method stub

}

public Sprite getRaindrop(float x, float y) {
return (new Sprite(x, y, snowTexture.deepCopy()));
}

@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,ITouchArea pTouchArea, float pTouchAreaLocalX, float pTouchAreaLocalY) {
if(pSceneTouchEvent.isActionDown()) {
// HERE I WANT PLACE CODE, THAT WILL START ANIMATION.
return true;
}
return false;
}
}

那么如何在点击时启动动画呢?我想做一些类似小卡通的东西。

最佳答案

在注册更新处理程序后的 onLoadScene 方法中禁用它。

mUpdateHandler.setEnabled(false);

并在 onAreaTouched 方法中启用它。

mUpdateHandler.setEnabled(true);

顺便说一句,我认为每次都在 onUpdate 方法中创建 Random 实例不是好的做法。

关于android - 使用 An Engine Live Wallpaper 扩展启动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8776713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com