Using the Frames library

edited August 2015 in Library Questions

I have started to have a play with the Frames library, to work with spritesheets. I have got my sprites working within the library example, but when I try to strip the code back to purely the code that I need, it doesn't run.

The error I am getting is 'null pointer exception' with the currentAnimation.advance(); line.

Pretty new to Processing, probably doing something stupid.

import java.util.List;
import org.dishevelled.processing.frames.Animation;
import org.dishevelled.processing.frames.Frames;

Frames frames;

Animation box;
Animation currentAnimation;
int px = width / 2;
int py = height / 2;
boolean right = true;

void setup()
{
  size(500,500);
  frameRate(25);
  background(20);
  frames = new Frames(this);
  List<PImage> boxFrames = frames.createFrameList("box.png", 0, 0, 200, 200, 10);

}

void draw()
{
  currentAnimation.advance();
  image(currentAnimation.getCurrentFrame(), px, py);
}

Answers

  • edited August 2015

    http://www.openprocessing.org/sketch/210240

    link to the original code before I started stripping it

  • "probably doing something stupid"
    I fear so... :-P Well, just usual beginner's mistakes, nothing to be ashamed of.
    I recommend taking a look at some of the first articles of http://forum.processing.org/two/categories/common-questions which tries to address some of these common mistakes.

    Among them:

    • You initialize global variables using width and height at declaration site. It won't work as it is computed before setup() is called, and that's in the size() call that these values are defined.
    • box and currenntAnimation variables are never initialized. That's the main cause of your NPE.

    Can't comment more as I don't know the library.

Sign In or Register to comment.