所以我有一段代码应该改变游戏对象的纹理,但不幸的是,它不起作用!
我的宝贝和积木并没有改变它们应该是什么!
我认为问题的一部分在于以下几段代码:
Game.java:
if(red == 255 && green == 255 & blue == 255) handler.addObject(new Block(xx*32, yy*32, 0, ObjectId.Block));
if(red == 128 && green == 128 & blue == 128) handler.addObject(new Block(xx*32, yy*32, 1, ObjectId.Block));
if(red == 0 && green == 0 & blue == 255) handler.addObject(new Player(xx*32, yy*32, handler, ObjectId.Player));
if(red == 255 && green == 255 & blue == 0) handler.addObject(new Treasure(xx*32, yy*32, 0, ObjectId.Treasure));
if(red == 255 && green == 254 & blue == 0) handler.addObject(new Treasure(xx*32, yy*32, 1, ObjectId.Treasure));
块:
public void render(Graphics g)
{
if(type == 0){//dirt
g.drawImage(tex.block[0], (int)x, (int)y, null);
}
if(type == 1){//grass
g.drawImage(tex.block[1], (int)x, (int)y, null);
}
}
宝:
public void render(Graphics g) {
if(i == 0)
{
g.drawImage(tex.treasure[0], (int)x, (int)y, null);
}
if(i == 1)
{
System.out.println("i = 1");
g.drawImage(tex.treasure[1], (int)x, (int)y, null);
}
}
纹理:
public void render(Graphics g) {
if(i == 0)
{
g.drawImage(tex.treasure[0], (int)x, (int)y, null);
}
if(i == 1)
{
System.out.println("i = 1");
g.drawImage(tex.treasure[1], (int)x, (int)y, null);
}
}
所以这些是我认为导致问题的代码部分。此外,代码中已声明i
和type
,我只是没有包含这些部分。
答案 0 :(得分:0)
我忘记了这一点:
type = type;