Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
246 views
in Technique[技术] by (71.8m points)

java - error message: "Pixels and SIZE cannot be resolved or are not a field"

I've run this code this in the newest version of Eclipse but in that, it did not specify this error message but did point at the pixels[x + y * width] = Sprite.grass.pixels[(x & 15) + (y & 15) *Sprite.grass.SIZE]; line of the code. So I didn't know what was the error so I ran it on an older version of the IDE, Kepler. In the IDE it gave this error message. I searched a lot on stackoverflow, there were several cases where people got the error message but most of them were related to importing android.R or something of that sort. But I'm not doing this for any android application, this is just for a normal project. So none of the solutions matched my problem.

The error message is pointing towards pixels and SIZE in Sprite class. If you need the SpriteSheet class code too let me know. There I was trying to load an image. This is all I can explain for now. So could anyone help me out, please?

package com.thecherno.rain.graphics;

 import java.util.Random;

public class Screen {
 
private int width, height;
public int[] pixels;
final int MAP_SIZE = 64;
final int MAP_SIZE_INT = MAP_SIZE - 1;

public int[] tiles = new int[MAP_SIZE * MAP_SIZE]; 
    
public Random random = new Random();

public Screen(int width, int height) {
    this.width = width;
    this.height = height;
    pixels = new int[width * height];
    
    for(int i = 0; i < MAP_SIZE * MAP_SIZE; i++) {
        tiles[i] = random.nextInt(0xffffff);
        tiles[0] = 0;
        
    }
}

public void clear() {
    for(int i = 0; i < pixels.length; i++) {
        pixels[i] = 0;
    }
}

public void render(int xoffset, int yoffset) {
 for(int y = 0; y < height; y++) {  
        for(int x = 0; x < width; x++) {
            pixels[x + y * width] = Sprite.grass.pixels[(x & 15) + (y & 15) *Sprite.grass.SIZE];

        }
        
    }
}
}









  package com.thecherno.rain.graphics;

 public class Sprite {
   public final int SIZE;
   private int x, y;
   public int[] pixels;
   private SpriteSheet sheet;
   
   
   public static Sprite grass = new Sprite(16, 0, 0, SpriteSheet.tiles);
   
   public Sprite(int size, int x, int y, SpriteSheet sheet) {
       SIZE = size;
       pixels = new int[SIZE * SIZE];
       this.x = x * size;
       this.y = y * size;
       this.sheet = sheet;
       load();
   }
   

   
   private void load() {
       for(int y = 0; y < SIZE; y++) {
           for(int x = 0; x < SIZE; x++) {
               pixels[x + y * SIZE] = sheet.pixels[(x + this.x) + (y + this.y) * sheet.SIZE];
           }
       }
   }
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...