main menu particle effects
This commit is contained in:
@@ -27,6 +27,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
private int windowSize = 1024;
|
||||
private int sampleRate;
|
||||
private long millisPerWindow;
|
||||
private boolean songChanged;
|
||||
private DecimalFormat df;
|
||||
private float[] PCM = new float[windowSize];
|
||||
private float[] frequencyBins = new float[windowSize / 2];
|
||||
@@ -102,14 +103,14 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
synchronizeBufferWithPlayback();
|
||||
}
|
||||
|
||||
private int calcBufferPosition() {
|
||||
private int calculateBufferPosition() {
|
||||
int offset = (int) alGetSourcef(sourceID, AL11.AL_SAMPLE_OFFSET);
|
||||
offset = (offset / windowSize) * windowSize;
|
||||
return offset;
|
||||
}
|
||||
|
||||
private boolean synchronizeBufferWithPlayback() {
|
||||
int bufferPos = calcBufferPosition();
|
||||
int bufferPos = calculateBufferPosition();
|
||||
synchronized (this) {
|
||||
if (bufferPos <= playingBuffer.limit() && bufferPos >= 0) {
|
||||
playingBuffer.position(bufferPos);
|
||||
@@ -121,7 +122,7 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMusic() {
|
||||
public void loadMusic() {
|
||||
Gdx.app.debug("PCMObtainer", "music set.");
|
||||
sourceID = -1;
|
||||
|
||||
@@ -129,8 +130,8 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
sampleRate = mc.getCurrentMusicHeader().getSampleRate();
|
||||
String millisPerWindowF = df.format(windowSize/(float) sampleRate);
|
||||
millisPerWindow = (long) (Float.valueOf(millisPerWindowF)*1000);
|
||||
|
||||
attemptToSync();
|
||||
songChanged = true;
|
||||
begin();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,14 +141,13 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
synchronized (this) {
|
||||
System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length);
|
||||
}
|
||||
|
||||
updated = false;
|
||||
}
|
||||
} else {
|
||||
for (int freqID = 0; freqID < frequencyBins.length; freqID++) {
|
||||
frequencyBins[freqID] = 0;
|
||||
}
|
||||
}
|
||||
updated = false;
|
||||
return frequencyBins;
|
||||
}
|
||||
|
||||
@@ -226,14 +226,14 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
public void update(Observable o, Object arg) {
|
||||
if (o == mc) {
|
||||
if (arg == mc.states.LOADED) {
|
||||
updateMusic();
|
||||
loadMusic();
|
||||
} else if (arg == mc.states.PLAYING) {
|
||||
attemptToSync();
|
||||
begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void attemptToSync() {
|
||||
private void begin() {
|
||||
if (mc.isPlaying()) {
|
||||
if (sourceID == -1) {
|
||||
try {
|
||||
@@ -252,4 +252,14 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
public void dispose() {
|
||||
streamReadThread.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAudioChanged() {
|
||||
if (songChanged) {
|
||||
songChanged = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,8 +5,12 @@ import java.util.Observer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffectPool.PooledEffect;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
@@ -16,6 +20,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.audio.MusicController;
|
||||
@@ -24,7 +29,7 @@ import zero1hd.rhythmbullet.audio.visualizer.DoubleHorizontalVisualizer;
|
||||
import zero1hd.rhythmbullet.desktop.audio.PCMObtainer;
|
||||
import zero1hd.rhythmbullet.graphics.ui.Page;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.MusicControls;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollingText;
|
||||
import zero1hd.rhythmbullet.util.ScreenConfiguration;
|
||||
|
||||
public class MainPage extends Page implements Observer {
|
||||
@@ -40,10 +45,15 @@ public class MainPage extends Page implements Observer {
|
||||
private TextButton quitButton;
|
||||
|
||||
private MusicControls musicControls;
|
||||
private ScrollText scrollText;
|
||||
private ScrollingText scrollText;
|
||||
|
||||
private DoubleHorizontalVisualizer dhv;
|
||||
|
||||
private boolean playParticles = true;
|
||||
private ParticleEffectPool particlePool;
|
||||
private Array<PooledEffect> particles;
|
||||
private float particleScale;
|
||||
|
||||
public MainPage(MusicController musicController, AudioMetadataController mmc, AssetManager assetManager, Skin skin, ScreenConfiguration screenConfiguration, ChangeListener playButtonListener, ChangeListener optionsButtonListener) {
|
||||
super(0, 0);
|
||||
this.mc = musicController;
|
||||
@@ -97,7 +107,7 @@ public class MainPage extends Page implements Observer {
|
||||
musicControls.setPosition((getWidth()-musicControls.getWidth() - 15f), 15f);
|
||||
addActor(musicControls);
|
||||
|
||||
scrollText = new ScrollText("...", "...", skin, false, true);
|
||||
scrollText = new ScrollingText("...", "...", skin, false, true, 1f/screenConfiguration.getTargetFramesPerSecond());
|
||||
scrollText.setWidth(0.5f*getWidth());
|
||||
scrollText.setPosition(15, getHeight() - scrollText.getHeight()-30f);
|
||||
addActor(scrollText);
|
||||
@@ -107,6 +117,11 @@ public class MainPage extends Page implements Observer {
|
||||
dhv.updateMusic();
|
||||
}
|
||||
|
||||
particles = new Array<>();
|
||||
ParticleEffect particle = assetManager.get("beateffect.p", ParticleEffect.class);
|
||||
particleScale = getWidth()/particle.findEmitter("main").getSpawnWidth().getHighMax();
|
||||
particlePool = new ParticleEffectPool(assetManager.get("beateffect.p", ParticleEffect.class), 0, 16);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,9 +133,40 @@ public class MainPage extends Page implements Observer {
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
dhv.draw(batch, parentAlpha);
|
||||
updateParticles(batch);
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
||||
|
||||
private void updateParticles(Batch batch) {
|
||||
if (mc.isPlaying() && playParticles) {
|
||||
if (particles.size < 16 && dhv.isSignificantBeat()) {
|
||||
PooledEffect particle = particlePool.obtain();
|
||||
particle.scaleEffect(particleScale);
|
||||
particles.add(particle);
|
||||
}
|
||||
if (particles.size > 0) {
|
||||
for (int i = particles.size - 1; i >= 0; i--) {
|
||||
PooledEffect particle = particles.get(i);
|
||||
particle.draw(batch, Gdx.graphics.getDeltaTime());
|
||||
if (particle.isComplete()) {
|
||||
particles.removeIndex(i);
|
||||
particle.free();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
public void stopParticles() {
|
||||
playParticles = false;
|
||||
for (int i = particles.size - 1; i >= 0 && particles.size > 0; i--) {
|
||||
particles.get(i).free();
|
||||
particles.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
dhv.dispose();
|
||||
@@ -131,6 +177,7 @@ public class MainPage extends Page implements Observer {
|
||||
@Override
|
||||
public void setCameraPositionToPage(Vector3 cameraPosition) {
|
||||
getStage().setScrollFocus(null);
|
||||
playParticles = true;
|
||||
super.setCameraPositionToPage(cameraPosition);
|
||||
}
|
||||
|
||||
|
@@ -128,7 +128,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
creditsPage = new CreditsPage(rhythmBullet.getSkin());
|
||||
stage.addActor(creditsPage);
|
||||
|
||||
musicSelectionPage = new MusicSelectionPage(rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), musicController, musicMetadataController, listeners.returnToMainPageListener, listeners.analysisPageButtonListener);
|
||||
musicSelectionPage = new MusicSelectionPage(rhythmBullet.getAssetManager(), rhythmBullet.getSkin(), musicController, musicMetadataController, rhythmBullet.getScreenConfiguration(), listeners.returnToMainPageListener, listeners.analysisPageButtonListener);
|
||||
stage.addActor(musicSelectionPage);
|
||||
|
||||
analysisPage = new AnalysisPage(musicController, musicMetadataController, rhythmBullet.getSkin(), listeners.musicSelectionPageButtonListener, listeners.confirmedSongListener);
|
||||
@@ -182,6 +182,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
setDisplayedPage(musicSelectionPage);
|
||||
mainPage.stopParticles();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -203,6 +204,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
setDisplayedPage(optionsPage);
|
||||
mainPage.stopParticles();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -224,6 +226,7 @@ public class MainScreen extends ScreenAdapter implements ResizeReadyScreen {
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
setDisplayedPage(creditsPage);
|
||||
mainPage.stopParticles();
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -37,7 +37,8 @@ import zero1hd.rhythmbullet.audio.AudioMetadataController;
|
||||
import zero1hd.rhythmbullet.audio.metadata.AudioMetadata;
|
||||
import zero1hd.rhythmbullet.audio.MusicController;
|
||||
import zero1hd.rhythmbullet.graphics.ui.Page;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollText;
|
||||
import zero1hd.rhythmbullet.graphics.ui.components.ScrollingText;
|
||||
import zero1hd.rhythmbullet.util.ScreenConfiguration;
|
||||
|
||||
public class MusicSelectionPage extends Page implements Observer {
|
||||
Preferences musicFileAnnotation;
|
||||
@@ -48,6 +49,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
private VerticalGroup vGroup;
|
||||
private TextButton back;
|
||||
private ScrollPane scrollPane;
|
||||
private ScreenConfiguration screenConfig;
|
||||
|
||||
private musicSelectionLoaderThread selectionLoaderThread;
|
||||
|
||||
@@ -65,7 +67,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
private float scrollTimer, scrollDelay = 0.2f, scrollDelMod, songSelectionTimer;
|
||||
private float musicSelectDelay;
|
||||
|
||||
public MusicSelectionPage(AssetManager assetManager, Skin skin, MusicController musicController, AudioMetadataController musicMetadataController, ChangeListener backButtonListener, ChangeListener beginButtonListener) {
|
||||
public MusicSelectionPage(AssetManager assetManager, Skin skin, MusicController musicController, AudioMetadataController musicMetadataController, ScreenConfiguration screenConfiguration, ChangeListener backButtonListener, ChangeListener beginButtonListener) {
|
||||
super(1, 0);
|
||||
this.assets = assetManager;
|
||||
this.mc = musicController;
|
||||
@@ -76,7 +78,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
selectables = new MusicSelectableButtonGroup();
|
||||
selectables.setMinCheckCount(0);
|
||||
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
||||
|
||||
this.screenConfig = screenConfiguration;
|
||||
scrollPane = new ScrollPane(vGroup, skin);
|
||||
scrollPane.setSize(0.45f*getWidth(), getHeight());
|
||||
scrollPane.setOverscroll(false, false);
|
||||
@@ -510,7 +512,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
}
|
||||
|
||||
private class InformationTable extends Table {
|
||||
private ScrollText songTitle;
|
||||
private ScrollingText songTitle;
|
||||
private Label author;
|
||||
private Label musicDuration;
|
||||
private Label previousTop;
|
||||
@@ -525,7 +527,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
setSize(width, height);
|
||||
subInformation = new Table(skin);
|
||||
albumCover = new Image(assets.get("defaultCover.png", Texture.class));
|
||||
songTitle = new ScrollText("", null, skin, true, true);
|
||||
songTitle = new ScrollingText("", null, skin, true, true, 1f/screenConfig.getTargetFramesPerSecond());
|
||||
author = new Label(null, skin, "sub-font", skin.getColor("default"));
|
||||
musicDuration = new Label(null, skin, "sub-font", skin.getColor("default"));
|
||||
previousTop = new Label(null, skin, "sub-font", skin.getColor("default"));
|
||||
|
Reference in New Issue
Block a user