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

2014/9/6

Help please im new at this and need help with music in my world

1
2
DragonGirl DragonGirl

2014/9/7

#
but can i get it to stop playing the same way
DragonGirl DragonGirl

2014/9/7

#
and how would i get the wombat to play the sound after eating exactly 8 leaves?
K_wow K_wow

2014/9/7

#
Yes, you can get the sound to stop playing the same way. You use and control the sound in the exact same way as you do in the world. As for the leaf count, create an integer that keeps track of how many leaves the wombat has eaten. Write code to test for a leaf that intersects the wombats image. If there is a leaf, then remove it and add to the wombat's leaf count. At the same time, check if the wombat's leaf count is 8. If it is, then play the sound.
DragonGirl DragonGirl

2014/9/7

#
how would i go about doing this?
K_wow K_wow

2014/9/8

#
Declare an int variable before the act method like this:
1
private int leafCount = 0;
Inside your act method, declare another variable that checks for a nearby leaf like this:
1
Actor leaf = getOneIntersectingObject(Leaf.class);
Now you need to check if the leaf is there like this:
1
2
3
if (leaf != null)
{
}
Inside the curly brackets, remove the leaf and add 1 to leafCount like this:
1
2
getWorld().removeObject(this);
leafCount++;
Still inside the curly brackets, directly below the "leafCount++;" line, check if leafCount equals 8, like this:
1
2
3
if (leafCount == 8)
{
}
Inside those curly brackets is where you put your code to play a sound and pause the game and whatever else you want to do when the wombat eats eight leaves.
Super_Hippo Super_Hippo

2014/9/8

#
Change
1
getWorld().removeObject(this);
to
1
getWorld().removeObject(leaf);
or you will remove the wombat.
K_wow K_wow

2014/9/8

#
Super_Hippo wrote...
Change
1
getWorld().removeObject(this);
to
1
getWorld().removeObject(leaf);
or you will remove the wombat.
Oops :P Yeah. Do what Super_Hippo said. Although if you ever do need to remove an actor using the "removeObject(this)" line of code, make sure to put "return;" on the next line to avoid the actor trying to do anything else that would require the actor to be in the world.
DragonGirl DragonGirl

2014/9/9

#
I want to ewokk to eat the wombat
DragonGirl DragonGirl

2014/9/9

#
I just want the Ewokk to play a sound when it eats the Wombat then stop playing the theme when the game is paused
Super_Hippo Super_Hippo

2014/9/9

#
Wait, who eats whom? If you have a reference to the sound object, you can stop it with the 'stop' or 'pause' method. danpost explained the procedure how to play a sound quite descriptive on the first page.
DragonGirl DragonGirl

2014/9/11

#
ok the WOMBAT the LEAVES the EWOKK eats the WOMBAT I tried that and it didnt play
Super_Hippo Super_Hippo

2014/9/11

#
So what do you have right now?
You need to login to post a reply.
1
2