gpt4 book ai didi

java - 基于box2D body 角度旋转textureRegion(无 Sprite )

转载 作者:行者123 更新时间:2023-12-02 03:04:58 24 4
gpt4 key购买 nike

我正在尝试使用 spriteBatcher 绘制方法,基于 box2d body 角度旋转纹理区域:

SpriteBatch.draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height,float scaleX, float scaleY, float rotation)

但是旋转结果如下所示

enter image description here我不知道我做错了什么,尝试了很多不同的 originX、originY 组合,但它总是被破坏。尝试将原点设置为 body 中心、左下角,但没有成功。

查看了文档,分析了 SpriteBatch.class,但我不清楚原因是什么。

如何正确旋转纹理?

编辑:我不能使用Sprite类,因为正在绘制的textureRegion是一个动画帧,并且据我所知,你不能用Sprite类制作动画帧

最佳答案

像这样设置box2d主体的多边形形状

float width=x,height=y;

PolygonShape polygonShape=new PolygonShape();
polygonShape.setAsBox(width/2, height/2,new Vector2(width/2,height/2),0);

PolygonShape 的 setAsBox 方法被重载。

关于java - 基于box2D body 角度旋转textureRegion(无 Sprite ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41878700/

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