-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable layer field right click, start to add animation system #3,
add R key to reset zoom and scroll, add Ctrl + X
- Loading branch information
Showing
5 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/main/java/fr/minuskube/editor/animation/FrameRepeat.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,24 @@ | ||
package fr.minuskube.editor.animation; | ||
|
||
public class FrameRepeat { | ||
|
||
private int start; | ||
private int end; | ||
private int times; | ||
|
||
private int currentTimes = 0; | ||
|
||
public FrameRepeat(int start, int end, int times) { | ||
this.start = start; | ||
this.end = end; | ||
this.times = times; | ||
} | ||
|
||
public int getStart() { return start; } | ||
public int getEnd() { return end; } | ||
public int getTimes() { return times; } | ||
|
||
public int getCurrentTimes() { return currentTimes; } | ||
public void setCurrentTimes(int currentTimes) { this.currentTimes = currentTimes; } | ||
|
||
} |
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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/fr/minuskube/editor/scene/object/SceneAnimation.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,69 @@ | ||
package fr.minuskube.editor.scene.object; | ||
|
||
import fr.minuskube.editor.animation.FrameRepeat; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SceneAnimation { | ||
|
||
private ObservableList<SceneAnimationFrame> frames; | ||
private List<FrameRepeat> repeats; | ||
|
||
private boolean playing = false; | ||
private boolean looping = false; | ||
|
||
private int width, height; | ||
private boolean autoCrop; | ||
private float speed = 1; | ||
|
||
private int currentFrame = 0; | ||
private float currentFrameState = 0; | ||
|
||
public SceneAnimation() { | ||
this.frames = FXCollections.observableArrayList(); | ||
this.repeats = new ArrayList<>(); | ||
} | ||
|
||
public void update() { | ||
SceneAnimationFrame frame = frames.get(currentFrame); | ||
|
||
currentFrameState += (1 / 60f) * speed; // TODO: Replace by deltaTime | ||
|
||
if(currentFrameState >= frame.getDuration()) { | ||
currentFrame++; | ||
|
||
for(FrameRepeat repeat : repeats) { | ||
if(repeat.getTimes() != -1 && repeat.getTimes() >= repeat.getCurrentTimes()) | ||
continue; | ||
|
||
if(currentFrame > repeat.getEnd()) | ||
currentFrame = repeat.getStart(); | ||
|
||
repeat.setCurrentTimes(repeat.getCurrentTimes() + 1); | ||
} | ||
|
||
currentFrameState = 0; | ||
} | ||
} | ||
|
||
public ObservableList<SceneAnimationFrame> getFrames() { return frames; } | ||
public List<FrameRepeat> getRepeats() { return repeats; } | ||
|
||
public boolean isPlaying() { return playing; } | ||
|
||
public boolean isLooping() { return looping; } | ||
public void setLooping(boolean looping) { this.looping = looping; } | ||
|
||
public int getWidth() { return width; } | ||
public void setWidth(int width) { this.width = width; } | ||
|
||
public int getHeight() { return height; } | ||
public void setHeight(int height) { this.height = height; } | ||
|
||
public float getSpeed() { return speed; } | ||
public void setSpeed(float speed) { this.speed = speed; } | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/fr/minuskube/editor/scene/object/SceneAnimationFrame.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,24 @@ | ||
package fr.minuskube.editor.scene.object; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
|
||
public class SceneAnimationFrame extends SceneImage { | ||
|
||
private float duration; | ||
private int offsetX, offsetY; | ||
|
||
public SceneAnimationFrame(File source) throws FileNotFoundException { | ||
super(source); | ||
} | ||
|
||
public float getDuration() { return duration; } | ||
public void setDuration(float duration) { this.duration = duration; } | ||
|
||
public int getOffsetX() { return offsetX; } | ||
public void setOffsetX(int offsetX) { this.offsetX = offsetX; } | ||
|
||
public int getOffsetY() { return offsetY; } | ||
public void setOffsetY(int offsetY) { this.offsetY = offsetY; } | ||
|
||
} |