I have a class Sword that is instantiated to create several objects in my game and hold them in an Array structure. How do I find the attributes each object of Sword class from another class ?
This code allocate and generate the Sword(s) Renderer class:
private List<Sword> swords = new ArrayList<Sword>();
Then in public Renderer() method I do:
for (int i = 0; i<10 ; i++ ) {
swords.add(new Sword());
}
In the render() they are displayed on the screen:
for (Sword sword : swords) {
sword.createMe();
}
And here is my Sword class:
public class Sword {
private TextureRegion sprite;
private static int xx;
private static int yy;
private int x;
private int y;
private int size;
private Random r;
public Sword() {
r = new Random();
x = (r.nextInt(10))*GameRender.tilesize;
y = (r.nextInt(10))*GameRender.tilesize;
size = GameRender.tilesize;
sprite =getSprite();
}
private TextureRegion getSprite() {
int id = r.nextInt(2);
System.out.println(id);
if(id==1){
sprite=AssetLoader.s1;
}else sprite=AssetLoader.s2;
return sprite;
}
public void createMeShape(){
GameRender.shapeRenderer.rect(x, y, size, size);
}
public void createMe() {
GameRender.batch.draw(sprite, x, y, size, size);
}
public static void Update() { }
}
So how do i find the value of x, y from the Render class (I cant use static because it will only find one swords position) for collision detection or how i check if swords x,y is same like playerx, playery (ints from GameRenderer class)?