java - Setting different Character Images -
im creating flappybird mock, 4 player each player has different image, have managed set image first 1 cant seem set them others.
i have class bird set first image , have main class created 3 other birds, not sure alter images , how should. appreciated.
public bird(int x, int y) { this.x = x; this.y = y; this.color = color.red; this.radius = 30; this.gravity = 6; this.isalive = true; this.score = 0; try { this.read = imageio.read(new file("src/images/41.png")); } catch (ioexception ex) { logger.getlogger(paintingpanel.class.getname()).log(level.severe, null, ex); } } public class flappybird extends timertask implements keylistener{ private bird flappya; private bird flappyb; private bird flappyc; private bird flappyd;
well considering path image same in code.
i'm not sure understand issue if want have different image each flappy should try :
public bird(int x, int y, string imagename) { this.x=x; this.y=y; this.color = color.red; this.radius = 30; this.gravity = 6; this.isalive = true; this.score = 0; try { this.read = imageio.read(new file("src/images/" + imagename + ".png")); } catch (ioexception ex) { logger.getlogger(paintingpanel.class.getname()).log(level.severe, null, ex); } }
then in main class instanciate flappy :
flappya = new bird(0, 0, "image0"); flappyb = new bird(0, 0, "image1"); flappyc = new bird(0, 0, "image2");
edit : images folder should @ root of project, "src" should used code source files.
Comments
Post a Comment