Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Dear Fellow Game Developers
i am newbie to Android Game Development,i like to know how we can develop a sprite rotate in circle on android,with help of libgdx, i do have a image in assets folder,cant load it in emulator,following code is using to load image in texture

texture = new Texture(Gdx.files.internal("1325603701_wordpress.png"));

share|improve this question
    
Are you having issues to load the texture or rotate the sprite? –  Gustavo Maciel Jan 8 '12 at 20:21
    
in both...i dont get image or rotate sprite –  Alex Mathew Jan 15 '12 at 18:53
    
Did you check for the answer and did you find the solution? –  Real_steel4819 Aug 11 at 13:42

4 Answers 4

Create your sprite as following

Texture glowBlock = new Texture(Gdx.files.internal("data/glow-block.png"));
Sprite  glowSprite = new com.badlogic.gdx.graphics.g2d.Sprite(glowBlock);

Then in your render method do this

@Override
public void render () {
    Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);
    spriteBatch.begin();
    spriteBatch.setColor(Color.WHITE);
    glowSprite.rotate((float) 45.0);
    glowSprite.draw(spriteBatch, 100);
    spriteBatch.end();
}

That should give you sprite rotated for 45 degrees

share|improve this answer
    
Is it working for you? –  Real_steel4819 Aug 11 at 13:42

Here is the simple way how can you rotate a sprite in libGDX. First you need to set the origin:

sprite.setOrigin(sprite.getWidth/2,sprite.getHeight/2);

Then you can rotate clockwise and anticlockwise according to your need:

sprite.rotate(2f); or sprite.rotate(-2f);
share|improve this answer

If by rotating in a circle you mean WALKING on top of the circumference of a circle, then I guess any of the answers correctly answered your question. So here is my add:

You can continue loading you texture with

texture = new Texture(Gdx.files.internal("1325603701_wordpress.png"));

but it is extremely recommended that you use the AssetManager. About it not loading in the emulator, check if your texture size is power of two. (Like 64x64)

Then create your sprite:

sprite = new Sprite(texture);

you'll possibly want to pass more arguments to cut the sprite, in case you're using a power of two texture for a non power of two sprite.

Create a helper variable on the class body, to keep track of the time, and one to say where will be the sprite center:

private float elapsedTime = 0.0f;
private Vector2 center = new Vector2(10, 10);

on render:

public void render () {
    final float speed = 30.0f; // in degrees per second
    final float radius = 10.0f; // the radius of the circle you'll be rotating
    float angle = elapsedTime * speed;
    Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);
    spriteBatch.setProjectionMatrix(camera.combined);
    spriteBatch.begin();
    sprite.setRotation(angle - 90);
    sprite.setPosition(center.x + radius * (float)Math.cos(angle * MathUtils.degrad), center.y + radius * (float)Math.sin(angle * MathUtils.degrad));
    sprite.draw(spriteBatch);
    spriteBatch.end();
}

This should work just fine.

share|improve this answer

Do it like this 1. Load your image into AssestLoader class and store it in sprite

sprite=new Sprite(AssestLoader.1325603701_wordpress);

2.Then set its size , position and color like this

sprite.setColor(1, 1, 1, 1);
sprite.setSize(sprite.getWidth(),sprite.getHeight());
sprite.setPosition((w / 2) - (sprite.getWidth() / 2), (h / 2)
                - (sprite.getHeight() / 2));

3- In your render method use the below code

batch.begin();
sprite.draw(batch);
batch.end();

4.Call the rotate method where u want to rotate

batch.begin();
this.rotate(deltatime); 
deltatime=deltatime+0.5f;       
batch.end();

and

public void rotate(float angle)
{
    sprite.setRotation(angle);

}

where deltatime is float value=1

Hope this Helps You.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.