public void updateVolume(float volume) { if (isPlaying()) { float effectiveVolume = volume * _volume; if (effectiveVolume > 0) sound.setVolume(effectiveVolume); else sound.stop(); } }
protected Sound prepareSound() { if (sound == null) { sound = loadSound(path()); sound.prepare(); } sound.setVolume(volume.get() * _volume); return sound; }
@Override public void release() { if (sound != null) { if (sound.isPlaying()) sound.stop(); sound.release(); sound = null; } }
public void jump() { Vec2 linearVelocity = getBody().getLinearVelocity(); linearVelocity.y = JUMP_SPEED; getBody().setLinearVelocity(linearVelocity); SOUND_JUMP.play(); }
private void complete() { complete = true; final Surface surface = surfaceLayer.surface(); surface.clear(); surface.drawImage(image, 20, 20, surface.width(), surface.height()); if (sound != null) { sound.play(); } }
@Override public void update(float delta) { super.update(delta); if (getBody().getPosition().y > 16) { PlayN.log().debug("Fallen!"); SOUND_OUCH.play(); dead = true; } }
@Override public void contact(PhysicsEntity other) { if (other instanceof Spike) { PlayN.log().debug("Ouch!"); SOUND_OUCH.play(); dead = true; } else if (other instanceof Block) { Block block = (Block) other; if (!block.isCollidable()) { exitReached = true; } } }
protected void startFadeIn(final float fadeMillis) { if (!isPlaying()) prepareSound().play(); sound.setVolume(0); // start at zero, fade in from there _faders.add( new Fader() { @Override public boolean update(int delta) { _elapsed += delta; float vol = Interpolator.LINEAR.apply(0, _range, _elapsed, fadeMillis); updateVolume(vol); return (vol >= _range); // we're done when the volume hits the target } protected final float _range = volume.get(); protected int _elapsed; }); }
@Override public boolean isPlaying() { return (sound == null) ? false : sound.isPlaying(); }
@Override protected Sound prepareSound() { Sound sound = super.prepareSound(); sound.setLooping(true); return sound; }