0

I want to know how to draw actors with textureRegion which is member of a group.

Let's say I've group of enemy.

private Group enemies;

private SpriteBatch batcher;

For just one Actor, I am drawing like this.

batcher = new SpriteBatch();
batcher.begin();
batcher.draw(textureRegion, actor position parameters vs vs);
batcher.end();

I want to know how to draw whole group's actors like this ? There is a method for drawing but this method does not take TextureRegion parameter.

public void draw(Batch batch,
        float parentAlpha)

Can I draw group with TextureRegion like this ?

enemies.draw(textureRegion, vs vs);
ekad
  • 14,436
  • 26
  • 44
  • 46
Emre Koç
  • 1,343
  • 1
  • 25
  • 44

1 Answers1

1

The whole point of using scene2D (which is where your Group comes from) is to add actors to a Stage in your game Screen. During the render() method, you call Stage.act(delta) and Stage.draw(). If you don't plan on doing that, why not simply use an ArrayList of TextureRegion or the "Enemy" class?

If you insist on using Group, you could try to loop through each member of the group and get its associated TextureRegion, but most Actors don't have direct access to it, unless you try to cast their getDrawable() into a TextureRegionDrawable, which is messy.

I would suggest you take a look at https://github.com/libgdx/libgdx/wiki/Scene2d. When used properly, Scene2D gives you a lot of power and convenience you won't get by using TextureRegion alone.

user3525774
  • 172
  • 7