我正在构建一个动态壁纸,我现在想要的只是一个简单的向右移动的精灵,仅此而已。我没有精灵的动画。壁纸加载,我看到了精灵,但它只是不动。我已经实现了 PathModifer 和 0 个错误,我已经检查了我的代码以查看大量示例和帖子,但我无法弄清楚它为什么没有移动。
这是我的整个班级:
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.IEntity;
import org.andengine.entity.modifier.LoopEntityModifier;
import org.andengine.entity.modifier.PathModifier;
import org.andengine.entity.modifier.PathModifier.IPathModifierListener;
import org.andengine.entity.modifier.PathModifier.Path;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.extension.ui.livewallpaper.BaseLiveWallpaperService;
import org.andengine.input.sensor.acceleration.AccelerationData;
import org.andengine.input.sensor.acceleration.IAccelerationListener;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.util.debug.Debug;
import org.andengine.util.modifier.ease.EaseSineInOut;
public class LiveWallpaperService extends BaseLiveWallpaperService implements IAccelerationListener{
//================================================================================
// Fields
//================================================================================
private static int CAMERA_WIDTH = 480;
private static int CAMERA_HEIGHT = 854;
private Scene mScene;
private BitmapTextureAtlas grass;
private ITextureRegion yourTextureRegion;
private BitmapTextureAtlas house;
private ITextureRegion houseRegion;
private BitmapTextureAtlas cloud1;
private ITextureRegion cloud1Region;
@Override
public EngineOptions onCreateEngineOptions() {
Camera mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions options = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
return options;
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.grass = new BitmapTextureAtlas(this.getTextureManager(), 1024, 512, TextureOptions.DEFAULT);
yourTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.grass, this, "bglwp.png", 0, 0);
this.mEngine.getTextureManager().loadTexture(this.grass);
this.cloud1 = new BitmapTextureAtlas(this.getTextureManager(), 256, 128, TextureOptions.DEFAULT);
cloud1Region = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.cloud1, this, "clld1.png", 0, 0);
this.mEngine.getTextureManager().loadTexture(this.cloud1);
this.house = new BitmapTextureAtlas(this.getTextureManager(), 512, 512, TextureOptions.DEFAULT);
houseRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.house, this, "front.png", 0, 0);
this.mEngine.getTextureManager().loadTexture(this.house);
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception {
final float x = CAMERA_WIDTH / 2 - yourTextureRegion.getWidth() /2;
final float y = CAMERA_HEIGHT / 2 - yourTextureRegion.getHeight() /2;
final float xx = CAMERA_WIDTH / 2 - houseRegion.getWidth() /2;
final float yy = CAMERA_HEIGHT / 2 - houseRegion.getHeight() /2;
mScene= new Scene();
mScene.setBackground(new Background(0.3294117f, 0.788235f, 0.909803f));
Sprite backgroundSprite = new Sprite(x - 80, y + 171, this.yourTextureRegion, getVertexBufferObjectManager());
mScene.attachChild(backgroundSprite);
Sprite foregroundSprite = new Sprite(xx + 10, yy + 80, this.houseRegion, getVertexBufferObjectManager());
mScene.attachChild(foregroundSprite);
Sprite cloud1Sprite = new Sprite( 100, 100, this.cloud1Region, getVertexBufferObjectManager());
final Path path = new Path(2).to(200, 200).to(20, 20);
cloud1Sprite.registerEntityModifier(new LoopEntityModifier(
new PathModifier(5, path, null, new IPathModifierListener() {
@Override
public void onPathStarted(final PathModifier pPathModifier, final IEntity pEntity) {
Debug.d("onPathStarted");
}
@Override
public void onPathWaypointStarted(PathModifier pPathModifier,
IEntity pEntity, int pWaypointIndex) {
}
@Override
public void onPathWaypointFinished(PathModifier pPathModifier,
IEntity pEntity, int pWaypointIndex) {
}
@Override
public void onPathFinished(PathModifier pPathModifier,
IEntity pEntity) {
}
}, EaseSineInOut.getInstance())));
mScene.attachChild(cloud1Sprite);
pOnCreateSceneCallback.onCreateSceneFinished(mScene);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
}
@Override
public void onAccelerationAccuracyChanged(AccelerationData pAccelerationData) {
// TODO Auto-generated method stub
}
@Override
public void onAccelerationChanged(AccelerationData pAccelerationData) {
// TODO Auto-generated method stub
}
}
任何人的帮助将不胜感激,谢谢。