简体   繁体   English

Java LibGDX中的旋转精灵

[英]Rotating sprite in java LibGDX

Have an asset class for the sprite which defines a texture, then the sprite as that texture sheet, with coordinates for the sheet. 对于定义纹理的精灵,有一个资产类,然后将该精灵作为该纹理工作表,并带有该工作表的坐标。 this is the sprite i am trying to rotate. 这是我要旋转的精灵。 I have been given the advice to rotate it using Sprite Batch (it rotates to my touch input: 我得到了使用Sprite Batch旋转它的建议(旋转到我的触摸输入:

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

and i get the error: 我得到错误:

The method draw(Texture, float, float, int, int, int, int) in the type SpriteBatch is not applicable for the arguments (Sprite, int, int, int, int, int, int, int, float) SpriteBatch类型的draw(Texture, float, float, int, int, int, int)不适用于参数(Sprite, int, int, int, int, int, int, int, float)

Is there a sort of way to cast a sprite to a texture or a better way to rotate it it just isn't working please help! 有没有一种将子画面投射到纹理的方法,或者有一种更好的旋转它的方法,它只是不起作用,请帮助!

You can simply use the rotate(float degrees) . 您可以简单地使用rotation(float degree) Sets the sprite's rotation in degrees relative to the current rotation. 设置精灵相对于当前旋转的旋转角度。

you must use the rotate(float degrees) in render method of your class. 您必须在类的render方法中使用rotation(float degree)。

as given in Sprite Class documentation Sprite类文档中所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM