Back to project page Flumpgdx.
The source code is released under:
Copyright (c) 2014 Daniyal Khan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softw...
If you think the Android project Flumpgdx listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.flumpgdx.display; /*from w w w. java2s .c o m*/ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Matrix3; import com.badlogic.gdx.math.Vector2; import com.flumpgdx.library.FlumpLayer; public class FlumpAnimation extends FlumpDisplayBundle { private int frameRate; private float frame; //User defined scale/rotation, negative values for scale will flip animation protected Matrix3 transformation; protected boolean dirty = false; //User defined translation, do this separately since this is usually applied protected Vector2 translation; public FlumpAnimation(FlumpLayer layer) { super(layer); this.frame = 0; transformation = new Matrix3(); translation = new Vector2(); } public void setframeRate(int frameRate) { this.frameRate = frameRate; } public void resetTransformation() { transformation.idt(); dirty = false; } public void scaleX(float scaleX) { transformation.scale(scaleX, 1); dirty = true; } public void scaleY(float scaleY) { transformation.scale(1, scaleY); dirty = true; } public void scale(float scaleX, float scaleY) { transformation.scale(scaleX, scaleY); dirty = true; } public void scale(float scale) { transformation.scale(scale, scale); dirty = true; } public void rotate(float radians) { transformation.rotateRad(radians); dirty = true; } public void translate(float x, float y) { translation.add(x, y); } public void translateX(float x) { translation.x += x; } public void translateY(float y) { translation.y += y; } public void setPosition(float x, float y) { translation.set(x, y); } public void update(float delta) { frame += delta * frameRate; if (frame > maxFrameCount()) frame = 0; super.update((int)frame); if (dirty) applyTransformation(transformation); applyTranslation(translation); } public boolean updateSingleRun(float delta) { frame += delta * frameRate; if (frame > maxFrameCount()) frame = maxFrameCount(); else { super.update((int)frame); } if (dirty) applyTransformation(transformation); applyTranslation(translation); //If finished then return true if (frame == maxFrameCount()) return true; return false; } public void updateSingleFrame(float frame) { super.update((int)frame); if (dirty) applyTransformation(transformation); applyTranslation(translation); } public boolean updateToFrame(float delta, float frameEnd) { frame += delta * frameRate; if (frame > frameEnd) frame = frameEnd; else if (frame < frameEnd) super.update((int)frame); if (dirty) applyTransformation(transformation); applyTranslation(translation); //If finished then return true if (frame == frameEnd) return true; return false; } public void draw(SpriteBatch batch) { super.draw(batch); } }