This site requires JavaScript, please enable it in your browser!
Greenfoot back
seandoesftw
seandoesftw wrote ...

2014/8/17

How do i move up/down while replacing the sprite

seandoesftw seandoesftw

2014/8/17

#
I can't seem to get my character to change to the back sprite and move that way Heres the code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class character here. * * @author (your name) * @version (a version number or a date) */ public class character extends Actor { /** * Act - do whatever the character wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.isKeyDown("w")) { int x = getX(); int y = getY(); setLocation(getX(), getY() + 4); World world = getWorld(); Actor charback; world.removeObject(this); world.addObject(new charback(), x, y); }else if(Greenfoot.isKeyDown("s")) { int x = getX(); int y = getY(); int ny = getY()+4; setLocation(x,ny); World world = getWorld(); Actor character; world.removeObject(this); world.addObject(new character(), x, y); }else if (Greenfoot.isKeyDown("d")){ move(4); int x = getX(); int y = getY(); World world = getWorld(); Actor charright; world.removeObject(this); world.addObject(new charright(), x,y); }else if (Greenfoot.isKeyDown("a")){ move(-4); int x = getX(); int y = getY(); World world = getWorld(); Actor charleft; world.removeObject(this); world.addObject(new charleft(), x,y); } } }
danpost danpost

2014/8/17

#
I would first suggest not to have four different actors for one character. All you need to do is change the image of the character to one of the four images by using 'setImage' when a new direction is detected. As far as not being able to have your character change to a back sprite and move that way ... your 'charback' class would need posted as the problem is probably there. Please use the 'code' link below the 'Post a reply' box to insert your code into your future posts.
You need to login to post a reply.