好的,我真的很困惑,我以前旋转过精灵,当船在海洋中移动时,我没有遇到任何问题,但由于某些原因,这次我遇到了一个非常大的问题。所以我在一个资源文件中创建了一个纹理,而不是静态纹理。我使用以下代码加载纹理:
class Assets{
Texture img;
public Assets(){
img = new Texture(Gdx.files.internal("images/PNG.png")然后我调用main类中的资源,方法是:
Assets assets = new Assets()然后我有一个类,它是这个主要角色的动画师,因为他的动画与其他角色有很大的不同。
class Animations{
Guy MYGUY;
Texture firstTexture;
ArrayList<Texture> running;
Sprite CurrentSprite;
public Animations(Texture standingStill, Guy myGuy){
MYGUY = myGuy;
firstTexture = standingStill;
running = new ArrayList<Texture>();
running.add(firstTexture);
CurrentSprite = new Sprite(firstTexture);
public void update (int direction, int state){
CurrentSprite.setPosition(MYGUY.X, MYGUY.Y)
// I have a switch here, but it does nothing yet because I haven't added in different actions for the character.
//However I do have a switch for direction, because that is important right now
switch(state){
case Guy.LEFT:
CurrentSprite.set rotation(180);
//yes there are more, but even rotating 180 won't work correctly
}然后我有一个渲染器类来绘制所有东西,我在一个名为myLand的对象中有一个对象MyGuy,并用以下命令绘制它:
myLand.GUY.animation.CurrentSprite(batch);所以我的问题出现在旋转上,当它旋转180度时,似乎总是围绕坐标(0,0)旋转,而不是围绕精灵的中心旋转。所以它通常会在我向右移动5次的地方结束,但如果我尝试向左移动,它确实会向后移动两倍的距离,但相机的位置保持不变,这个人通常会从屏幕的左侧或右侧消失。
发布于 2014-12-15 17:18:20
试一试
sprite.setOriginCenter();这应该会有帮助
发布于 2014-03-03 23:55:13
不用旋转子画面,只需用这一行将其翻转即可:
CurrentSprite.flip(true, false);第一个布尔值是X翻转(这是您在向左转时希望设置为true的值),第二个布尔值是Y翻转。
https://stackoverflow.com/questions/22151098
复制相似问题