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

2018/3/25

How to let a actor walk?

LMT LMT

2018/3/25

#
Hey there, I want that Mario is changing his image every step so I took a code from Youtube but Greenfoot say that it can´t find image "Run10". The problem is that I just want to use the images "Run1" up to "Run3". This is the code I took: private GreenfootImage images = new GreenfootImage; private int jeda=10,num=0,deltax=10; public void addedToWorld(World Back) { for(int i=0; i<3; i++) { images = new GreenfootImage("Run1" +i+".png"); } setImage(images); } public void act() { if(jeda==0)jeda=10; if(jeda==1){ setImage(images); num++; if(num>=3)num=0; setLocation(getX()+deltax,getY()); } if(jeda==2)jeda--; }
danpost danpost

2018/3/25

#
LMT wrote...
Hey there, I want that Mario is changing his image every step so I took a code from Youtube but Greenfoot say that it can´t find image "Run10". The problem is that I just want to use the images "Run1" up to "Run3". This is the code I took: << Code Omitted
Try this in the loop:
images = new GreenfootImage("Run"+(1+i)+".png");
Yehuda Yehuda

2018/3/25

#
Am I missing something here? In the end of the execution of the for-loop 'images' will be set to "Run3.png" and nothing else.
danpost danpost

2018/3/25

#
Yehuda wrote...
Am I missing something here? In the end of the execution of the for-loop 'images' will be set to "Run3.png" and nothing else.
Yes. You are missing the arrays. Quote the code post to view actual code (code tags were not used -- properly). Actually, tags were used; however, the first was a capitalized "Code" (which should be "code") and the closing tag was a closing "quote" tag (which does not close code).
Yehuda Yehuda

2018/3/26

#
Right when I saw the answer was "Yes" I understood. Because I've seen before how all brackets are removed if they're not between the code tags. Now that can make sense (although it always did).
danpost danpost

2018/3/26

#
Yehuda wrote...
Right when I saw the answer was "Yes" I understood. Because I've seen before how all brackets are removed if they're not between the code tags. Now that can make sense (although it always did).
Lol -- I realize now that my copy/paste operation before editing the line also did not get the array brackets. My edited line should read:
images[i] = new GreenfootImage("Run"+(1+i)+".png");
You need to login to post a reply.