TowerDefense图像导入(eclipse,java)

时间:2015-02-28 15:11:53

标签: java eclipse image

我一直在使用eclipse进行塔防游戏,我无法打印出我的塔的照片。以下是主塔类的一些代码:

public class MainTower {    
    public String TextureFile = ""; 
    public Image texture;
    //tower array that holds up to 150 towers
    public static final MainTower[] towerList = new MainTower[150];          
    //Connecting the Lightning tower to the Main tower class    
    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;
    } 
}

位置正确图像是25x25 png图像,称为Lightning。以下是布局类中的一些代码:

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);         
        }     
   }
}

我在屏幕底部创建了一个网格(框),我希望放置我的塔,以便玩家可以选择。所以我想知道我哪里出错了所以图片不会打印出来。

这是LightningTower类:

//Creating a class for Lightning towers
public class LightningTower extends MainTower{

//Setting up Lightning tower id
    public LightningTower(int id){
        super(id);
    }
}

0 个答案:

没有答案