PImage won't draw to screen (Involves Tables and Classes)

I'm trying to make a guitar hero/rock band like game where the player presses keys when the notes go over the hit boxes, but for some reason the images for the notes stopped displaying. I am currently loading the note data from a .csv file (x,y,speed,colour), and displaying the image based on that data.

Again the problem that I am having is that the images aren't displaying.

Code That Runs:

Song song1 = new Song(10000,"data\\songs\\test.csv");
void setup(){
  size(1080,720);
  frameRate(30);
  audio = new PlayAudio(this);
  song1.load_notes();
}
void draw(){
  background(255);
  song1.draw_notes();
}
abstract class _Note{
  float posx,posy,speed;
  String colour;
  PImage img1,img2,img3,img4;
  void loadImg(){
    img1 = loadImage("graphics\\r_note1.png");
    img2 = loadImage("graphics\\b_note1.png");
    img3 = loadImage("graphics\\g_note1.png");
    img4 = loadImage("graphics\\y_note1.png");
  }
  void display(){
    if(colour=="red")image(img1,posx,posy);
    if(colour=="blue")image(img2,posx,posy);
    if(colour=="green")image(img3,posx,posy);
    if(colour=="yellow")image(img4,posx,posy);
  }
}
class Note extends _Note{
  Note(float x, float y, float s, String c){
    posx = x; posy = y; speed = s; colour = c;
  }
}
abstract class _Song{
  Table note_table;
  String file;
  ArrayList<Note>note = new ArrayList<Note>();
  int seconds,time;
  void load_notes(){
    note_table = loadTable(file,"header");
    for(int i=0;i<note_table.getRowCount();i++){
      note.add(new Note(note_table.getFloat(i,0),note_table.getFloat(i,1),note_table.getInt(i,2),note_table.getString(i,3)));
    }
    for(int i=0;i<note.size();i++){
      note.get(i).loadImg();
    }
    println("|--X--|--Y--|Speed|Colour|");
    for(int i=0;i<note.size();i++){
      println(note.get(i).posx+"|"+note.get(i).posy+"|"+note.get(i).speed+"|"+note.get(i).colour);
    }
  }
  void draw_notes(){
    for(int i=0;i<note.size();i++){
      note.get(i).display();
      //note.get(i).posx = note.get(i).posx+note.get(i).speed;
    }
  }
}
class Song extends _Song{
  Song(int s,String f){
    seconds = s; file = f;
  }
}

CSV File:

--x--,-y-,speed,colour,
100,100,5,red
200,200,5,blue
300,300,5,green
400,400,5,yellow
Tagged:

Answers

  • where are your images? the code is expecting them in the data/graphics directory under the project directory.

  • The images are there, I checked to make sure that the images are correct and could be loaded in a seperate test sketch.

  • Answer ✓
    if(colour=="red")image(img1,posx,posy);
    

    use .equals() to compare strings

  • That fixed it, thanks :)

Sign In or Register to comment.