我有一个精灵的以下代码,可以使用Andengine跟踪路径。我需要改变沿路径()移动的精灵的速度(速度)。有谁知道如何沿路径改变速度?
private void follow_path5(final AnimatedSprite tSprite,int i) {
final Path path = new Path(5)
.to(20, startY)
.to(416.0f, startY)
.to(20.0f, startY)
.to(416.0f,startY)
.to(20.0f,startY);
// Add the proper animation when a waypoint of the path is passed.
tSprite.registerEntityModifier(new PathModifier(30.0f, path, null, new IPathModifierListener() {
@Override
public void onPathStarted(final PathModifier pPathModifier, final IEntity pEntity) {
}
@Override
public void onPathWaypointStarted(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) {
switch(pWaypointIndex) {
case 0: case 1: case 2: case 3:
final long[] frameDurations = new long[3];
Arrays.fill(frameDurations, 500);
tSprite.animate(frameDurations, 2, 4, true);
break;
case 4: case 5: case 6: case 7:
final long[] frameDurations1 = new long[3];
Arrays.fill(frameDurations1, 500);
tSprite.animate(frameDurations1, 5, 7, true);
break;
case 8: case 9: case 10: case 11:
final long[] frameDurations2 = new long[3];
Arrays.fill(frameDurations2, 500);
tSprite.animate(frameDurations2, 2, 4, true);
break;
case 12: case 13: case 14:
final long[] frameDurations3 = new long[3];
Arrays.fill(frameDurations3, 500);
tSprite.animate(frameDurations3, 5, 7, true);
break;
}
}
@Override
public void onPathWaypointFinished(final PathModifier pPathModifier, final IEntity pEntity, final int pWaypointIndex) {
}
@Override
public void onPathFinished(final PathModifier pPathModifier, final IEntity pEntity) {
}}));
scene.attachChild(asprVamp[i]);
}
答案 0 :(得分:2)
您只能给出移动的持续时间,每个路径修改器1个。因此,如果您想在不同的路径点上使用不同的速度,则必须创建不同的路径修改器。
答案 1 :(得分:2)
您可以使用SequenceEntityModifier
将不同的实体修饰符合并为一个,这将满足您的请求,因为每个PathModifier
可以有不同的时间长度。
Path a = new Path(2).to(0, 0).to(400,0);
Path b = new Path(2).to(400, 0).to(800, 0);
IEntityModifier[] modifier = new IEntityModifier[2];
modifier[0] = new PathModifier(3, a);
modifier[1] = new new PathModifier(1, b);
IEntityModifier entMod = new SequenceEntityModifier(modifier);
entity.registerEntityModifier(entMod);
scene.attachChild(entity);
答案 2 :(得分:1)
我对类似问题的解决方案是从原始修饰符派生并为通过的时间添加一个因子:
@Override
public float onUpdate(float pSecondsElapsed, IEntity pItem) {
return super.onUpdate(pSecondsElapsed*frequency, pItem);
}