samedi 28 février 2015

TowerDefense image import (eclipse,java)

I've been working on a tower defense game using eclipse and I cannot manage to print out the picture of my tower. Here is some code from the main tower class :




`public class MainTower {
public String TextureFile = "";
public Image texture;

public static final MainTower[] towerList = new MainTower[150];

public static final MainTower towerOfLight = new LightningTower(0).getTextureFile("Lightning");
public MainTower(int id) {
if(towerList[id] != null){
System.out.println("[Tower Initialization] Two towers with the same id" + id);

else{
towerList[id] = this;
this.id = id;
}
}
public MainTower getTextureFile(String str) {
this.TextureFile = str;
this.texture = new ImageIcon("/res/tower/" + this.TextureFile + "png").getImage();
return null;
} }


The location is correct the image is a 25x25 png image called Lightning. Here is some code from the layout class :



> `for(int x = 0; x<15; x++){
> for(int y = 0; y<2; y++){
> if(MainTower.towerList[x *2 +y] != null) GUI.drawImage(MainTower.towerList[x * 2 + y].texture, (int) (12 + 12 + 250 + 40 + 12 +(x * towerWidth)), (12*50) + 20 + (y *(int)towerHeight), null);
>
> GUI.drawRect((int) (12 + 12 + 250 + 40 + 12 +(x * towerWidth)), (int) ((12*50) + 20 + ((y * towerHeight))),(int)towerWidth,(int)towerHeight);
> }
> }
> }`


I've created a grid (boxes) at the bottom of the screen where I wish to place my towers so the player can choose. So I was wondering where am i going wrong so the picture doesn't print out.


Aucun commentaire:

Enregistrer un commentaire