I just master programming, and this question arose: There is a certain class Plane, in which there are 3 textures and you need to choose a random one. And there is the main class Main, in which you need to change this texture at some point. Here is what I have:
public class Plane extends Sprite { private Array<TextureRegion> colorArray; private TextureRegion color; public TextureRegion redPlane; public TextureRegion bluePlane; public TextureRegion greenPlane; public Plane(TextureRegion color) { redPlane = ResourceManager.getInstance().getTextureRegion("planeRed"); greenPlane = ResourceManager.getInstance().getTextureRegion("planeGreen"); bluePlane = ResourceManager.getInstance().getTextureRegion("planeBlue"); colorArray = new Array<TextureRegion>(); this.color = color; } public void randomColor(){ colorArray.addAll(redPlane,greenPlane,bluePlane); color = colorArray.random(); } In the main class:
private Plane plane; ... plane = new Plane(); ... plane.randomColor();
randomColor()method. Just what kind of method are you calling:colorArray.random()? Standard arrays have no such method. If you want to get a random element of the array, you need to do this:java.util.Random rand = new Random(); color = array[rand.nextInt(array.length)]java.util.Random rand = new Random(); color = array[rand.nextInt(array.length)]. rand can be (and usually better) created separately, for example, in the constructor. - m. vokhmMyClass instance = new MyClass(parameter);- m. vokhmBufferedReader reader = new BufferedReader(new FileReader("File.txt"));. Here, theBufferedReaderconstructor is passed as a parameter an object of theFileReaderclass, created bynew FileReader("File.txt")constructornew FileReader("File.txt")- m. vokhmrandomColor()when you need. What exactly does not work? - m. vokhm