0
votes

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:

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)

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!

1
you're getting this problem because you're trying to pass in ints to a function that is expecting floats. Try casting all the ints to floats when you call the function. - clearlyspam23
@clearlyspam23 i tries this 'game.batch.draw(FarmerAsset.upFarmer1, farmerX, farmerY, (float)85, (float)85, (float)170, (float)170, (float)1, (float)angleDegrees); ' but i still get the same error is it not to do with using sprite oppesed to texture? - user3165683
according to the SpriteBatch docs, there should be an overload that takes a TextureRegion, and according to the Sprite docs, Sprites should be TextureRegions, so that should work. It looks to me like you might be missing a parameter on your function call (you have scaleX but no scaleY) - clearlyspam23
@clearlyspam23 my friend thank u, u r a genius i'll happily accep your answer if u would like - user3165683

1 Answers

1
votes

You can simply use the rotate(float degrees) . 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.

as given in Sprite Class documentation