【发布时间】:2014-04-04 18:10:08
【问题描述】:
好的,所以我真的很困惑,我以前旋转过精灵并且没有任何问题,比如在船穿过海洋时旋转它,但由于某种原因,这次我遇到了一个非常大的问题。所以我在资产文件中创建了一个纹理,而不是静态纹理。我使用以下内容加载纹理:
class Assets{
Texture img;
public Assets(){
img = new Texture(Gdx.files.internal("images/PNG.png")
然后我通过调用来调用主类中的资产:
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) 而不是精灵的中心旋转。所以它通常会在我向右移动五点的地方结束,但是如果我尝试向左移动,它会向后加倍距离,但相机位置保持不变,而且那个人通常会从左侧或右侧消失屏幕。
【问题讨论】:
-
尝试使用
rotate(...)方法而不是setRotation(...)。与setOrigin(widthSprite\2, heightSprite\2). -
我会在几个小时后回到我的电脑前尝试一下,谢谢你的想法。
-
只是出于好奇:对于动画,您使用的是 libgdx 动画吗?如果不是,我建议这样做。
-
不,我不是,只是因为主要角色动画的复杂性,但是对于其余的角色,我是,但是是的,谢谢你的建议
标签: java android rotation libgdx sprite