我正试图在catmull-romspline中移动一个对象。最好的方法是什么?这是密码。样条线已经绘制好了,我只是不知道如何将实体(在本例中是一个动画蝎子)移动到点的方向。我已经尝试了一些只使用纹理或精灵的东西,但不知怎么的,它对蝎子不起作用。谢谢你的帮助(可能是一些资源来帮助我更好地理解它?)
package levels;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.CatmullRomSpline;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import enemy.scorpionEntity.Scorpion;
public class levelGenerator extends ApplicationAdapter {
SpriteBatch batch;
Scorpion scorpion;
LevelOne level;
Vector2 position = LevelOne.levelOnePath().first();
Vector2 size = new Vector2(95, 95);
private int waypoint = 0;
private CatmullRomSpline<Vector2> levelPath;
private ShapeRenderer shapeRenderer;
private float SPEED = 100;
public levelGenerator() {
}
public void create(){
batch = new SpriteBatch();
level = new LevelOne();
scorpion = new Scorpion(position, size, "assetsPack/scorpions/scorpionRunning/scorpionPack.atlas");
level.createBackground();
scorpion.create();
shapeRenderer = new ShapeRenderer();
levelPath = new CatmullRomSpline<Vector2>(new Vector2[] {
new Vector2(0, 150),
new Vector2(250, 150),
new Vector2(360, 175),
new Vector2(410, 225),
new Vector2(440, 300),
new Vector2(500, 360),
new Vector2(525, 375),
new Vector2(625, 350),
new Vector2(700, 325),
new Vector2(750, 325),
new Vector2(800, 375),
new Vector2(850, 500),
new Vector2(900, 550),
new Vector2(1000, 550),
new Vector2(1100, 550),
new Vector2(1200, 500),
new Vector2(1400, 500),
}, true);
}
@Override
public void render(){
batch.begin();
level.renderBackground();
scorpion.animate();
batch.end();
int k = 100;
Vector2[] points = new Vector2[k];
for(int i = 0; i < k; ++i){
points[i] = new Vector2();
levelPath.valueAt(points[i], ((float)i)/((float)k-1));
}
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
for(int i = 0; i < k-1; ++i){
shapeRenderer.line(points[i], points[i+1]);
}
shapeRenderer.end();
}
}
暂无答案!
目前还没有任何答案,快来回答吧!