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

2012/4/20

Some objects appear "late"

legX legX

2012/4/20

#
Hello ! I have some problem with an object (image) which does not appear in the right moment... but later. Why ? Here is a simplified version of my code : if (true) { addObject(new Score("You win!"); Greenfoot.playSound("welldone.wav"); GreenfootSound soundyes=new GreenfootSound("applaus.wav"); soundyes.play(); while(soundyes.isPlaying()) {} if (true) { Greenfoot.playSound("crush.wav"); } } else { // basically the same thing} Greenfoot.stop(); I want each of the 3 sounds to be played sequentially and not in the same time... Here I hear the first two sounds, then the score appears and the third sound is heard. I have checked that the score IS created at the right moment, so why does it not appear then ?? I have had the same kind of problem somewhere else but this was easier to explain, I hope tu understand in the same time all my problems ;) Thank you very much !
danpost danpost

2012/4/21

#
Obviously, the code you provided is in the world class. For the Score appearing late issue, add a 'repaint();' statement after the 'addObject(new Score("You win!");' statement. For the sounds issue, they way you are going about this part is not really the proper way (because it hogs up CPU time -- but we can compensate, a little).
GreenfootSound soundOne = new GreenfootSound("welldone.wav");
GreenfootSound soundTwo = new GreenfootSound("applause.wav");
GreenfootSound soundThree = new GreenfootSound("crush.wav");
soundOne.play();
while (soundOne.isPlaying()) delay(1);
soundTwo.play();
while (soundTwo.isPlaying()) delay(1);
soundThree.play();
The delay(1)s allow background stuff to run between checks (frees up the CPU a little).
legX legX

2012/4/21

#
Thank you very much for this (very quick) response ! It worked, although I had to precise 'Greenfoot.delay(1)'. I am working on a new version of my Othello, available soon !! (still a few hours...)
You need to login to post a reply.