2014-09-22 70 views
0

我正在使用基于文本的RPG,并在处理该错误时遇到此错误。编译错误:不是语句

package game; 

import java.awt.image.BufferedImage; 
import java.awt.image.DataBufferInt; 

/** 
* 
* @author Pyro 
*/ 
public class SpriteSheetLoader { 
    public int[] sheetPixels; 
    public int[] pixels; 
    int x, y, sheetWidth; 

    public SpriteSheetLoader(BufferedImage sheet){ 
     BufferedImage image = new BufferedImage(sheet.getWidth(), sheet.getHeight(), BufferedImage.TYPE_INT_ARGB); 
     image.getGraphics().drawImage(sheet, 0, 0, null); 

     sheetPixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData(); 

     sheetWidth = sheet.getWidth(); 

    } 

    public void grabTile(int tile, int width, int height) { 
     sheetPixels = new int[width * height]; 

     int xTile = tile % 16; 
     int yTile = tile % 16; 

     for (int y = 0; y < height; y++) { 
      for (int x = 0; x < width; x++) { 
       int value = pixels[(x + (y * width))] * sheetPixels[((x + (xTile * width)) + (y + (yTile * height)) * sheetWidth)]; 
      } 
     } 
    } 



} 

错误周围七号线出现了,我似乎无法找出

+0

显示的错误是什么?我没有看到在这段代码中定义的'sheetPixels','pixels'或'sheetWidth',所以我不能告诉你这些是否有问题。 – mkobit 2014-09-22 23:58:18

+0

这是说,第七行不是一个声明 – Pyrosix 2014-09-22 23:59:02

+0

该行没有任务。看起来你只是在计算一个值。 – 2014-09-22 23:59:37

回答

0

你不这样做你的代码的任何转让的问题:

pixels[(x + (y * width))] * sheetPixels[((x + (xTile * width)) + (y + (yTile * height)) * sheetWidth)]; 

您需要用这里的值做一些事情,我不确定你想做什么(比如可能在数组中设置值),所以这里只是一个例子。

int value = pixels[(x + (y * width))] * sheetPixels[((x + (xTile * width)) + (y + (yTile * height)) * sheetWidth)]; 

除了你的错误,你做sheetPixels = new int[width * height];后立即尝试取出数据与sheetPixels[...]数组,但比你问一个完全不同的问题。