我正在嘗試創建一個非常簡單的瓷磚貼圖系統,幾周前我遇到了問題,並在此處詢問,但最近我已將其重寫並停止正常工作。爲什麼不能顯示整個瓷磚地圖?
請注意,我使用的是slick2D,所以如果你想重現這一點,那麼你必須把代碼放在你的主要渲染循環中。
陣列
public static int[][] map = {{1,1,1,1,1,2,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,0,0,0,0,0,1}};
瓷磚地圖循環。
int x = 0;
int y = 0;
int I = 0;
int II = 0;
while(y <= 7){
while(x <= 12){
if(map[y][x] == 0){
Image img = new Image("res/tile1.png");
img.draw(II,I);
}
if(map[y][x] == 1){
Image img = new Image("res/tile0.png");
img.draw(II,I);
}
if(map[y][x] == 2){
Image img = new Image("res/tile3.jpg");
img.draw(II,I);
}
x++;
II = x * 100;
}
y++;
I = y * 100;
}
截圖http://puu.sh/iIf9r/42c3b6f4db.png
感謝。
繪製方法是自定義的嗎?從快速檢查中,環路應該正常運行。再來看看,我下面的答案是正確的。 –