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

2015/4/16

FatCat Scenario

HTown_Diva HTown_Diva

2015/4/16

#
Can someone tell me how to shorten a music file. When my cat stops dancing in the FatCat scenario, I want the music to stop also. Thank you in advance.
danpost danpost

2015/4/17

#
To be able to stop the music you must retain a reference to it. You can only do that by creating a GreenfootSound object. Keep it in a field and use it to start and stop the music:
1
2
3
4
5
// instance field (in Cat class -- I would guess)
private GreenfootSound music = new GreenfootSound("whatever.mp3");
// in act or method it calls
if (/** cat starts dancing */) music.play();
if (/** cat stops dancing */) music.stop();
HTown_Diva HTown_Diva

2015/4/23

#
Thank you!
HTown_Diva HTown_Diva

2015/4/23

#
Now I have a new problem. When I try to compile the following code, I get an error message (invalid method declaration; return type required), What am I doing wrong? public class LazyCat extends MyCat { /** * Act - do whatever the LazyCat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { sleep(5); } public act() { if (isSleepy()) { sleep(5); } else { dance(); } } }
davmac davmac

2015/4/23

#
Please use code tags when posting code: You seem to have two 'act' methods:
1
public void act()
1
public act()
You cannot have two methods with the same name (and signature); probably you should have put the code for the second 'act' method inside the first 'act' method instead of declaring the method again. Also, the second method declaration does not have a return type specified, which is what the error message is telling you. If a method doesn't return anything you should write 'void' as the return type (as in the first declaration of 'act' that you do have).
HTown_Diva HTown_Diva

2015/4/23

#
Thank you davmac for telling me how to post things and your suggestion to put the second code in the first one worked.
You need to login to post a reply.