gpt4 book ai didi

android - 在libGDX中画线动画

转载 作者:太空狗 更新时间:2023-10-29 16:29:51 27 4
gpt4 key购买 nike

我正在 libGdx 中做第一场比赛。我必须像this video一样画线动画

这是我画线的代码

Vector2 start = new Vector2(10, 10);
Vector2 end = new Vector2(100,100);
ShapeRenderer shapeRenderer=new ShapeRenderer();
shapeRenderer.setProjectionMatrix(cam.combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.line(start, end);
shapeRenderer.end();

我可以在两点之间画直线,但需要有绘图动画。

有什么帮助吗?

最佳答案

根据您的代码,您只需要使坐标值动态化:

Vector2 startPt = null;
Vector2 endPt = null;
Vector2 movingPt = null;

void myInit()
{
startPt = new Vector2(10, 10);
endPt = new Vector2(100, 100);
movingPt = new Vector2(startPt.x, startPt.y);
}

void update( float delta )
{
// add your animation here, below is an example
float PixelsPerSecond = 100f;
float dt = delta * PixelsPerSecond;
if ( movingPt.x < endPt.x ) movingPt.x += dt;
else movingPt.x = endPt.x;
if ( movingPt.y < endPt.y ) movingPt.y += dt;
else movingPt.y = endPt.y;
}

void draw()
{

// add code here (or in a base class) to clear the screen (once) each loop

ShapeRenderer shapeRenderer=new ShapeRenderer();
shapeRenderer.setProjectionMatrix(cam.combined);
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
shapeRenderer.setColor(Color.BLACK);
shapeRenderer.line(startPt, movingPt);
shapeRenderer.end();
}

关于android - 在libGDX中画线动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42251146/

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