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

2014/4/6

Coding error

GamesGrinder1998 GamesGrinder1998

2014/4/6

#
I have another problem in my game, a terminal window pops up and says "MyGame 2 cannot be cast to MyGame"...i don't know what's wrong but MyGame2 is the multiplayer version of the game whilst MyGame is obviously the single player....how can i fix this problem....i need help asap cos i have an assignment due next week
danpost danpost

2014/4/6

#
You will have to show the troublesome code with some context.
GamesGrinder1998 GamesGrinder1998

2014/4/6

#
danpost wrote...
You will have to show the troublesome code with some context.
don't worry i fixed it...thanks for trying to help do you know how to make sound play when i press run in greenfoot and stop when i press to start the actual game...i used Greenfoot.playSound("file") and when i press compile, i started playing automatically and when i pressed to play the game, it was still playing...do you know how to fix this problem???
danpost danpost

2014/4/6

#
You cannot control the sound when using the 'playSound' method of the Greenfoot class. You need to create a GreenfootSound object and use methods from its class to start and stop it. You can use a 'static' field to hold the GreenfootSound object in your World class. If you need to stop it from the 'StartButton' class (or whatever - or from any class other than that World class), you can use 'WorldClassName.sound.stop();' (NOTE: I names the GreenfootSound field 'sound'; and 'WorldClassName' should be the name of your world). You can use the World class method 'started' to put any code you want to execute when the 'Run' button is pressed.
GamesGrinder1998 GamesGrinder1998

2014/4/6

#
danpost wrote...
You cannot control the sound when using the 'playSound' method of the Greenfoot class. You need to create a GreenfootSound object and use methods from its class to start and stop it. You can use a 'static' field to hold the GreenfootSound object in your World class. If you need to stop it from the 'StartButton' class (or whatever - or from any class other than that World class), you can use 'WorldClassName.sound.stop();' (NOTE: I names the GreenfootSound field 'sound'; and 'WorldClassName' should be the name of your world). You can use the World class method 'started' to put any code you want to execute when the 'Run' button is pressed.
sorry i don't really understand it, how would the code look
danpost danpost

2014/4/6

#
GamesGrinder1998 wrote...
sorry i don't really understand it, how would the code look
Please refer to the GreenfootSound API documentation for the constructor(s) and method(s) available.
You need to login to post a reply.