Hi, I needed some help with my new game... I am trying to change the image when the character moves up and down, and I am having trouble creating the variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class PlayerChar here. * * @author (your name) * @version (a version number or a date) */ public class PlayerChar extends Actor { /** * Act - do whatever the PlayerChar wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ charImage++; public void act() { if (Greenfoot.isKeyDown( "up" )) { int x = getX(); int y = getY(); int ny = getY()- 1 ; setLocation(x,ny) ; GreenfootImage charImage = new GreenfootImage( "IMG_1191.PNG" ); } if (Greenfoot.isKeyDown( "down" )) { int x = getX(); int y = getY(); int ny = getY()+ 1 ; setLocation(x,ny) ; GreenfootImage charImage = new GreenfootImage( "IMG_1190.PNG" ); } if (Greenfoot.isKeyDown( "left" )) { int x = getX(); int y = getY(); int ny = getX()- 1 ; setLocation(ny,y) ; } if (Greenfoot.isKeyDown( "right" )) { int x = getX(); int y = getY(); int ny = getX()+ 1 ; setLocation(ny,y) ; } setImage(charImage); } } |