Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

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

$
0
0

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(); }

Note Code:

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

Song Code:

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


Viewing all articles
Browse latest Browse all 2896

Trending Articles