Last active
November 29, 2016 15:15
-
-
Save zacharycarter/ed614bf3cd6c23a82f445056e7dea7ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.carterza.world; | |
import com.badlogic.gdx.graphics.Color; | |
import com.badlogic.gdx.graphics.g2d.Animation; | |
import com.badlogic.gdx.graphics.g2d.Batch; | |
import com.badlogic.gdx.graphics.g2d.TextureRegion; | |
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | |
import com.badlogic.gdx.math.Vector3; | |
import com.badlogic.gdx.scenes.scene2d.Actor; | |
import com.badlogic.gdx.scenes.scene2d.Group; | |
import com.badlogic.gdx.scenes.scene2d.InputEvent; | |
import com.badlogic.gdx.scenes.scene2d.InputListener; | |
/** | |
* Created by zachcarter on 11/29/16. | |
*/ | |
public class AnimatedOverworldActor extends Actor { | |
Overworld overworld; | |
Animation animation; | |
ShaderProgram selectionShader; | |
boolean targeted = false; | |
float animationTime = 0; | |
public AnimatedOverworldActor (final Overworld overworld, Animation animation, ShaderProgram selectionShader) { | |
this.overworld = overworld; | |
this.animation = animation; | |
this.selectionShader = selectionShader; | |
final AnimatedOverworldActor self = this; | |
addListener(new InputListener() { | |
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { | |
System.out.println("down"); | |
overworld.setSelectedActor(self); | |
return true; | |
} | |
public void touchUp (InputEvent event, float x, float y, int pointer, int button) { | |
System.out.println("up"); | |
} | |
public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) { | |
System.out.println("entered"); | |
targeted = true; | |
} | |
public void exit (InputEvent event, float x, float y, int pointer, Actor fromActor) { | |
System.out.println("exited"); | |
targeted = false; | |
} | |
}); | |
} | |
@Override | |
public void act (float delta) { | |
super.act(delta); | |
animationTime += delta; | |
} | |
@Override | |
public void draw (Batch batch, float parentAlpha) { | |
TextureRegion region = animation.getKeyFrame(animationTime); | |
Color color = getColor(); | |
batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); | |
boolean currentlyActive = overworld.getSelectedActor().equals(this); | |
if(targeted && !currentlyActive) { | |
region.getTexture().bind(); | |
selectionShader.begin(); | |
selectionShader.setUniformf("u_color", new Vector3(1,1,0)); | |
selectionShader.setUniformi("u_texture", 0); | |
selectionShader.end(); | |
batch.setShader(selectionShader); | |
batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), | |
getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); | |
batch.setShader(null); | |
} else if(currentlyActive) { | |
region.getTexture().bind(); | |
selectionShader.begin(); | |
selectionShader.setUniformf("u_color", new Vector3(0,1,0)); | |
selectionShader.setUniformi("u_texture", 0); | |
selectionShader.end(); | |
batch.setShader(selectionShader); | |
batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), | |
getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); | |
batch.setShader(null); | |
} else { | |
batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), | |
getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment