Mario Semper
Mario Semper

Reputation: 561

Sub coordinate system in Actor

is it possible to use a sub coordinate system in an actor?

I'd like to implement a simple flat progress bar, that draws an filled rect according to the current state of the progress bar.

My problem: If i add a progress bar to a stage, that has for example a FitViewPort(10, 10) and the progress bar has a size of 10 width and 1 height, i've only the posibility to display 10 different states of the progress bar: [-][-][-][-][-][-][-][-][-][-].

Can i use a different coordinate system in the progress bar,for example 100x10, so that i can display 100 different states? The size of the progress bar should be defined in the stage's coordinate system 10x10.

Thanks Mario

Upvotes: 0

Views: 97

Answers (1)

m.antkowicz
m.antkowicz

Reputation: 13571

the best solution will be to keep actor's (x, y) in some variabes and then calculate position on stage using localToStageCoordinates. Then you can also scale local coordinates. The following code is an example how to achieve it:

    Actor a = new Actor();

    //...

    float actorX = 0, actorY = 86;
    float xScl = 1, yScl = 0.1f;

    //... //modify inside-actor coordinates

    Vector2 positionOnStage = a.localToStageCoordinates( new Vector2(actorX * xScl, actorY * yScl )); //calculate stage coordinates fom local actor's

Upvotes: 1

Related Questions