Niranjana
Niranjana

Reputation: 536

Fixed size object array in LibGdx

I want to create an object array with fixed size in LibGDX,where I want to add fixed number and type of object.

I used to create object array like this.

    private Array<Coin> coins = new Array<Coin>();
    coin = objectFactory.createCoin();//method to create single coin object
    coins.add(coin);

But with this type of array,I could add objects dynamically only. Adding size like this also have no effect.

    private Array<Coin> coins = new Array<Coin>(10);

How can I define a object array thats size and elements are fixed?

Upvotes: 1

Views: 191

Answers (1)

Chaoz
Chaoz

Reputation: 2260

Pretty sure that you can use a regular array to achieve what you want:

private Coin coins[] = new Coin[10]; // size 10
coins[0] = objectFactory.createCoin(); // set element at first position
Coin coin = coins[5]; // get element at position 5 (6th element)

Upvotes: 1

Related Questions