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

2023/12/17

i got a code that makes it animate but i already got the mirrord images but how to code it in that when i go left that image player_0 shows instead of player 0 and olso whit 0 1 2 3 4 5

bonamin bonamin

2023/12/17

#
import greenfoot.*; public class MAN extends Actor { private GreenfootImage images1=new GreenfootImage; private GreenfootImage images=new GreenfootImage; private int jeda=10,num=0,deltax=30; public void addedToWorld(World latar) { for (int i=0;i<images.length;i++) { images=new GreenfootImage("Player"+i+".png"); } setImage(images); } private int speed = 7; //Change number for other speed private int vspeed = 0; //Change number for other fall speed private int vspeedplus = 1; //How fast you fall evry sec private int jumpHeight = -20; //How high you jump public void act() { checkFalling(); if (Greenfoot.isKeyDown("right") ) { move(speed); if(jeda==0)jeda=10; if(jeda==1) { setImage(images); num++; if(num>=images.length)num=0; } if(jeda>0)jeda--; } if (Greenfoot.isKeyDown("left") ) { move(-speed); if(jeda==0)jeda=10; if(jeda==1) { setImage(images); num++; if(num>=images.length)num=0; } if(jeda>0)jeda--; } if (Greenfoot.isKeyDown("up")&&(onGround()==true)) { vspeed = jumpHeight; fall(); } } boolean onGround() { Actor under = getOneObjectAtOffset (0, getImage().getHeight()/2, Ground.class); return under != null; } public void fall() { setLocation (getX(), getY() + vspeed); vspeed = vspeed + vspeedplus; } public void checkFalling() { if(onGround()== false) { fall(); } if(onGround()== true) { vspeed = 0; } if(getY() > 790) { setLocation(70,623); } } }
danpost danpost

2023/12/20

#
bonamin wrote...
i got a code that makes it animate but i already got the mirrord images but how to code it in that when i go left that image player_0 shows instead of player 0 and olso whit 0 1 2 3 4 5 << Code Omitted >>
You have yet to initialize the second set of images.
You need to login to post a reply.