added proper rotation to visualizer
This commit is contained in:
parent
3e05e66a38
commit
6fb5744048
@ -8,37 +8,46 @@ import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import zero1hd.rhythmbullet.audio.MusicDataPack;
|
||||
|
||||
public class HorizontalVisualizer extends VisualizerCore {
|
||||
public class BasicVisualizer extends VisualizerCore {
|
||||
private Pixmap pixmap;
|
||||
private Texture bar;
|
||||
private int barWidth;
|
||||
private int binsPerBar;
|
||||
private int spaceBetweenBars;
|
||||
private Texture[] textures;
|
||||
private Sprite[] bars;
|
||||
private int smoothRange;
|
||||
private float barHeightMultiplier;
|
||||
private float rotation;
|
||||
private Vector2 angleRad;
|
||||
|
||||
public HorizontalVisualizer() {
|
||||
public BasicVisualizer() {
|
||||
super(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()/2, 0, 0);
|
||||
barHeightMultiplier = Gdx.graphics.getHeight()*0.01f;
|
||||
pixmap = new Pixmap(2, 2, Format.RGBA8888);
|
||||
pixmap.setColor(Color.GRAY);
|
||||
pixmap.fill();
|
||||
bar = new Texture(pixmap);
|
||||
pixmap.dispose();
|
||||
barCount = 70;
|
||||
barWidth = MathUtils.ceil((float) width/(float) barCount);
|
||||
spaceBetweenBars = (barWidth-2);
|
||||
barWidth -= spaceBetweenBars;
|
||||
smoothRange = 4;
|
||||
angleRad = new Vector2(MathUtils.cosDeg(rotation), MathUtils.sinDeg(rotation));
|
||||
textures = new Texture[barCount];
|
||||
bars = new Sprite[barCount];
|
||||
for (int i = 0; i < bars.length; i++) {
|
||||
bars[i] = new Sprite(bar);
|
||||
|
||||
|
||||
for (int i = 0; i < textures.length; i++) {
|
||||
textures[i] = new Texture(pixmap);
|
||||
bars[i] = new Sprite(textures[i]);
|
||||
}
|
||||
|
||||
updatePositionInfo();
|
||||
pixmap.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,4 +97,14 @@ public class HorizontalVisualizer extends VisualizerCore {
|
||||
bar.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public void updatePositionInfo() {
|
||||
int barSpace;
|
||||
for (int i = 0; i < bars.length; i++) {
|
||||
barSpace = i*(barWidth+spaceBetweenBars);
|
||||
bars[i].rotate(rotation);
|
||||
|
||||
bars[i].setPosition(xPos + barSpace*angleRad.x, yPos + barSpace*angleRad.y);
|
||||
}
|
||||
}
|
||||
}
|
6
core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java
Normal file → Executable file
6
core/src/zero1hd/rhythmbullet/ui/components/Visualizer.java
Normal file → Executable file
@ -2,12 +2,12 @@ package zero1hd.rhythmbullet.ui.components;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
|
||||
import zero1hd.rhythmbullet.audio.visualizer.HorizontalVisualizer;
|
||||
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
|
||||
|
||||
public class Visualizer extends Actor {
|
||||
private HorizontalVisualizer hVis;
|
||||
private BasicVisualizer hVis;
|
||||
|
||||
public Visualizer() {
|
||||
hVis = new HorizontalVisualizer();
|
||||
hVis = new BasicVisualizer();
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||
import zero1hd.rhythmbullet.RhythmBullet;
|
||||
import zero1hd.rhythmbullet.audio.MusicDataPack;
|
||||
import zero1hd.rhythmbullet.audio.SongController;
|
||||
import zero1hd.rhythmbullet.audio.visualizer.HorizontalVisualizer;
|
||||
import zero1hd.rhythmbullet.audio.visualizer.BasicVisualizer;
|
||||
import zero1hd.rhythmbullet.events.OnDifferentSongListener;
|
||||
import zero1hd.rhythmbullet.screens.PreGameScreen;
|
||||
|
||||
@ -32,10 +32,10 @@ public class MainPage extends Page implements OnDifferentSongListener {
|
||||
private WidgetGroup playButton;
|
||||
|
||||
private SongController sc;
|
||||
private HorizontalVisualizer hvisual;
|
||||
private BasicVisualizer hvisual;
|
||||
|
||||
public MainPage(RhythmBullet core, Vector3 targetPosition, SongController sc) {
|
||||
hvisual = new HorizontalVisualizer();
|
||||
hvisual = new BasicVisualizer();
|
||||
this.sc = sc;
|
||||
sc.addOnDifferentSongListener(this);
|
||||
hvisual.setMDP(sc.getCurrentSong());
|
||||
|
Loading…
Reference in New Issue
Block a user