added actor version of visualizer

This commit is contained in:
Harrison Deng 2017-09-12 16:12:34 -05:00
parent 658f4fa807
commit d26cef0cb1
5 changed files with 135 additions and 15 deletions

View File

@ -107,4 +107,32 @@ public class BasicVisualizer extends VisualizerCore {
bars[i].setPosition(xPos + barSpace*angleRad.x, yPos + barSpace*angleRad.y);
}
}
@Override
public void setHeight(int height) {
updatePositionInfo();
super.setHeight(height);
}
@Override
public void setWidth(int width) {
updatePositionInfo();
super.setWidth(width);
}
@Override
public void setxPos(int xPos) {
updatePositionInfo();
super.setxPos(xPos);
}
@Override
public void setyPos(int yPos) {
updatePositionInfo();
super.setyPos(yPos);
}
public void setRotation(float rotation) {
this.rotation = rotation;
}
}

View File

@ -21,15 +21,11 @@ public class VisualizerCore implements Disposable {
this.yPos = y;
}
public void update() {
public void calculate() {
if (cmi != null) {
if (cmi.getPlaybackIndexPosition() > cmi.getCurrentReadWindowIndex()) {
cmi.readSamples(audioPCM);
fft.realForward(audioPCM);
// Gdx.app.debug("Visualizer", "Proper read");
} else {
// System.out.println(audioPCM[16]);
// Gdx.app.debug("Visualizer", "Not reading so music can catch up.");
}
}
}
@ -47,4 +43,20 @@ public class VisualizerCore implements Disposable {
public void dispose() {
}
public void setxPos(int xPos) {
this.xPos = xPos;
}
public void setyPos(int yPos) {
this.yPos = yPos;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
}

View File

@ -35,7 +35,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.getViewport().apply();

View File

@ -1,13 +1,94 @@
package zero1hd.rhythmbullet.ui.components;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Widget;
import zero1hd.rhythmbullet.audio.MusicDataPack;
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
public class Visualizer extends Actor {
private BasicVisualizer hVis;
public class Visualizer extends Widget {
private BasicVisualizer vis;
private Vector2 coords;
private Vector2 size;
public Visualizer() {
hVis = new BasicVisualizer();
vis = new BasicVisualizer();
coords = new Vector2();
size = new Vector2();
}
@Override
public void draw(Batch batch, float parentAlpha) {
vis.render(batch, parentAlpha);
super.draw(batch, parentAlpha);
}
@Override
public void act(float delta) {
vis.calculate();
super.act(delta);
}
public void setMDP(MusicDataPack mdp) {
vis.setMDP(mdp);
}
@Override
public void setX(float x) {
coords.set(getX(), getY());
getStage().stageToScreenCoordinates(coords);
vis.setxPos((int) coords.x);
super.setX(x);
}
@Override
public void setY(float y) {
coords.set(getX(), getY());
getStage().stageToScreenCoordinates(coords);
vis.setyPos((int) coords.y);
super.setY(y);
}
@Override
public void setWidth(float width) {
size.set(getWidth(), getHeight());
getStage().stageToScreenCoordinates(size);
vis.setWidth((int) size.x);
super.setWidth(width);
}
@Override
public void setHeight(float height) {
size.set(getWidth(), getHeight());
getStage().stageToScreenCoordinates(size);
vis.setWidth((int) size.y);
super.setHeight(height);
}
@Override
public void setSize(float width, float height) {
setHeight(height);
setWidth(width);
}
@Override
public void setPosition(float x, float y) {
setX(x);
setY(y);
super.setPosition(x, y);
}
@Override
public void setRotation(float degrees) {
vis.setRotation(degrees);
super.setRotation(degrees);
}
@Override
public void layout() {
vis.updatePositionInfo();
super.layout();
}
}

View File

@ -20,6 +20,7 @@ import zero1hd.rhythmbullet.audio.SongController;
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
import zero1hd.rhythmbullet.events.OnDifferentSongListener;
import zero1hd.rhythmbullet.screens.PreGameScreen;
import zero1hd.rhythmbullet.ui.components.Visualizer;
public class MainPage extends Page implements OnDifferentSongListener {
private Image title;
@ -32,14 +33,14 @@ public class MainPage extends Page implements OnDifferentSongListener {
private WidgetGroup playButton;
private SongController sc;
private BasicVisualizer hvisual;
private Visualizer hvisual;
public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) {
hvisual = new BasicVisualizer();
hvisual = new Visualizer();
this.sc = sc;
sc.addOnDifferentSongListener(this);
hvisual.setMDP(sc.getCurrentSong());
addActor(hvisual);
title = new Image(core.getAssetManager().get("title.png", Texture.class));
title.setPosition(10, getHeight() - title.getHeight()-30);
addActor(title);
@ -124,8 +125,6 @@ public class MainPage extends Page implements OnDifferentSongListener {
@Override
public void draw(Batch batch, float parentAlpha) {
hvisual.update();
hvisual.render(batch, parentAlpha);
super.draw(batch, parentAlpha);
}