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.

I am intending to build a circular menu, with menu items equally distributed around the circle. When clicking on a menu item the circle should rotate so that the selected item is facing the top. I am using libgdx and I am not very familiar with the Actors concept, so I intuitivly tried to implement an Actor, who is drawing a texture and then transforming it by using Actions, with no success:

    class CircleActor extends Actor {

    @Override
    public void draw(SpriteBatch batch, float parentAlpha) {
        batch.draw(texture1, 100, 100);
    }

    @Override
    public Actor hit(float x, float y) {
        return this;
    }

}

and the rotate action:

    CircleActor circleActor = new CircleActor();
    circleActor.action(Forever.$(RotateBy.$(0.1f, 0.1f)));
    // stage.addActor();
    stage.addActor(circleActor);

The texture is rectangular, but it doe not work. 1. What is wrong? 2. Is it a good approach to solve the task?

Thanks!

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

In your draw method, you are currently drawing without taking into account the position or rotation of your actor. You are just telling it to draw the texture at 100, 100. So moving or rotating the actor have obviously no effect.

Update your batch.draw call to pass in the rotation and position of your actor. You can choose between these overloaded methods to do the work.

batch.draw(Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) 
batch.draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) 
batch.draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise) 

See the SpriteBatch documentation or read about SpriteBatch on the wiki.

With that said your method of doing it looks good. You may want to investigate if you can use some existing actors instead. There are actors like Button, ImageButton, Image, Label etc. that you probably can reuse. Just be warned that some of them don't support rotating. (You can rotate them, but they will do as you; ignore the angle when drawing :p ).

share|improve this answer
    
Reusing other Actors is what I did in the End, so that I used a WidgetGroup as container to hold the menu items and Image as an rotation enabled Menu Item. I was just confused that some Actors do not support rotation, but that is probably because Skins are not going well together with such transformation. Thx. –  joecks Jun 27 '12 at 11:21
    
Nice you found a solution. –  Matsemann Jun 27 '12 at 12:00
add comment

To rotate them in a circular manner, you have to set your actor's origin first:

image.setOrigin(image.getWidth() / 2,image.getHeight() / 2);
image.addAction(Actions.rotateBy(360, .2f));
share|improve this answer
add comment

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.