3/13/2024 0 Comments Greenfoot play sound loop![]() Public boolean onWall() // test to see if the man class is on the wall classĪctor Wall = getOneObjectAtOffset( 0, 0, Wall.class) Īctor Door = getOneObjectAtOffset( 0, 0, Door. The for loop would then repeatedly execute code to add one image icon to the. It can be used, possibly, to create the display of the number of lives left. It does not have a value of it own - so, using it for your lives or a counter just makes no sense. SetLocation(getX(),getY()+1) // move downĪctor Fire = getOneObjectAtOffset( 0, 0, Fire.class) The for statement is a code structure that controls the flow of execution of your code. SetLocation(getX()+1,getY()) // move Right What you need to do is tell it to play once. I may be wrong, but it seems to me that your problem is that you keep indefinitely call play() in an act method somewhere (Im guessing in your world). When the state changes, change the value of the field and if the field after being changed is true, then play the sound. There is also a play() method (which I think you already knew) which will play the sound. ![]() Then you just need a boolean field to track the hover state of the mouse on the object. SetLocation(getX()-1,getY()) // get loaction of x and y, then move -1 on x move Left I want the audio file to play only once when someone hover overs it. * the 'Act' or 'Run' button gets pressed in the environment.ĬheckKeyPress() // call this method to work One thing I can say, is that you probably do not need to loop the sound as the act method will be executed continuously while the scenario is running and the actor is in the world. Maybe you need to see if a sound is not already playing before starting one as well. Well if you want your sound to play in a loop the easyest way would be to use the playLoop mehtod of the GreenfootSound API. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) Or that you need to see if a sound is playing before trying to stop it. Is there a way to add a sound based on an object class that you land on? and that it will only play every 5 seconds ? so far I got it to play when I'm on the object but it plays so fast.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |