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

2013/11/13

Switching image problem

ProForces ProForces

2013/11/13

#
Hey guys. Im makin a mario game for my java practice. Now i have a problem. I want when i press "right", every 100 nanos, my class image changes. With the purpose that it looks like he walks. Can someone tell me how? And you can just call it image 1 and 2. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class small_right here. * * @author (your name) * @version (a version number or a date) */ public class small_right extends Mario { /** * Act - do whatever the small_right wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(Greenfoot.isKeyDown("right")) { move(5); setImage("small_run_right.png"); //i want here a delay setImage("small_right.PNG"); if(Greenfoot.isKeyDown("left")) { move(-5); setImage(new GreenfootImage("small_run_left.png")); setImage(new GreenfootImage("small_left.PNG")); } } }
AnnetePeter AnnetePeter

2013/11/13

#
hey, how'd you get you java programmer. could you please give me a link?
danpost danpost

2013/11/13

#
Add an instance Boolean field to the class...call it 'usingLeftImage'. If time to change image and its value is false, set its value to true and set the left image; if time to change image and its value is true, set its value to false and set the right image.
ProForces ProForces

2013/11/14

#
Okej, I will try. Thnx for your help!
You need to login to post a reply.