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

2013/2/15

Sound Plays at Delay

Qslick Qslick

2013/2/15

#
I have a sound play when my Actor gets hurt but it plays a little bit after the event takes place. Is this my code or is my computer just slow. will it upload with the delay? public void hurt() { Actor spike = getOneObjectAtOffset(0, getImage().getHeight()/2, spike.class); if(spike == null) { } else { setLocation(40 , 408); helpCounter += 1; Greenfoot.playSound("Electricity2.wav"); } }
Gevater_Tod4711 Gevater_Tod4711

2013/2/15

#
Your code is not the problem. In a such short code with a linear term (means there are no loops or such things) the term is not the problem. But it's also not probable that the sound takes that long to load. Maybe the sound is played directly but there are a view milliseconds at the beginning of it where nothing is played. I think that would be the most likly answer.
danpost danpost

2013/2/15

#
It may be that it takes a moment for the sound file to load. You can declare a class field to hold a GreenfootSound object so it is in memory when you need it.
//declare at the top of the class
static GreenfootSound electricity = new GreenfootSound("Electricity2.wav");
//then, instead of 'Greenfoot.playSound( ... )', use
electricity.play();
You need to login to post a reply.