-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>me.hsgamer</groupId> | ||
<artifactId>hscore</artifactId> | ||
<version>4.4.4-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>hscore-animate</artifactId> | ||
</project> |
43 changes: 43 additions & 0 deletions
43
animate/src/main/java/me/hsgamer/hscore/animate/Animation.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package me.hsgamer.hscore.animate; | ||
|
||
import java.util.List; | ||
|
||
public class Animation<T> { | ||
private final List<T> frames; | ||
private final long periodMillis; | ||
private Long startMillis; | ||
|
||
public Animation(List<T> frames, long periodMillis) { | ||
if (frames.isEmpty()) { | ||
throw new IllegalArgumentException("Frames cannot be empty"); | ||
} | ||
if (periodMillis <= 0) { | ||
throw new IllegalArgumentException("Period must be positive"); | ||
} | ||
|
||
this.frames = frames; | ||
this.periodMillis = periodMillis; | ||
} | ||
|
||
public List<T> getFrames() { | ||
return frames; | ||
} | ||
|
||
public T getFrame(int index) { | ||
return frames.get(index); | ||
} | ||
|
||
public T getCurrentFrame() { | ||
long currentMillis = System.currentTimeMillis(); | ||
if (startMillis == null) { | ||
startMillis = currentMillis; | ||
} | ||
long diff = currentMillis - startMillis; | ||
int index = (int) (diff / periodMillis) % frames.size(); | ||
return frames.get(index); | ||
} | ||
|
||
public void reset() { | ||
startMillis = null; | ||
} | ||
} |
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