Thursday, May 15, 2014

I solved *my* problem...

Turns out my problem was just a minor issue -- I put "Sprite.sheet.SIZE" when it should have just been "sheet.SIZE".  :sigh:

Anyway, here's my Sprite class if you are interested:
package com.version001.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); // Sprite.grass is 16x16 and in column 0, row 0

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

No comments:

Post a Comment