MakeTiles: Animation: draw the frames for different times during the animation
This commit is contained in:
parent
56a4b3da27
commit
8acf22d790
3 changed files with 31 additions and 12 deletions
|
@ -81,10 +81,21 @@ class Animation extends TileImage
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
|
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY)
|
||||||
{
|
{
|
||||||
if (frames.isEmpty()) { return; }
|
int t = 0;
|
||||||
frames.get(0).frame.drawTo(gr, destX, destY, srcX, srcY);
|
for (int i = 0; i < frames.size(); i++) {
|
||||||
|
Frame f = frames.get(i);
|
||||||
|
int d = t + f.duration;
|
||||||
|
if (time < d) {
|
||||||
|
f.frame.drawTo(gr, destX, destY, srcX, srcY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
t = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw nothing
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -135,9 +135,12 @@ public class MakeTiles
|
||||||
|
|
||||||
if (m.dest instanceof Animation) {
|
if (m.dest instanceof Animation) {
|
||||||
Animation ani = (Animation) m.dest;
|
Animation ani = (Animation) m.dest;
|
||||||
for (Animation.Frame f : ani.frames) {
|
int t = 0;
|
||||||
|
for (int i = 0; i < ani.frames.size(); i++) {
|
||||||
|
Animation.Frame f = ani.frames.get(i);
|
||||||
TileImageSprite s = (TileImageSprite) f.frame;
|
TileImageSprite s = (TileImageSprite) f.frame;
|
||||||
m.ref.drawTo(gr, s.offsetX, s.offsetY, 0, 0);
|
m.ref.drawWithTimeTo(gr, t, s.offsetX, s.offsetY, 0, 0);
|
||||||
|
t += f.duration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -7,7 +7,12 @@ public abstract class TileImage
|
||||||
{
|
{
|
||||||
public static final int STD_SIZE = 16;
|
public static final int STD_SIZE = 16;
|
||||||
|
|
||||||
public abstract void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY);
|
public abstract void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY);
|
||||||
|
public final void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
|
||||||
|
{
|
||||||
|
drawWithTimeTo(gr, 0, destX, destY, srcX, srcY);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the end-time of the animation frame identified by frameTime;
|
* @return the end-time of the animation frame identified by frameTime;
|
||||||
* -1 if not an animation, or if frameTime is past the end of the animation
|
* -1 if not an animation, or if frameTime is past the end of the animation
|
||||||
|
@ -21,12 +26,12 @@ public abstract class TileImage
|
||||||
TileImage above;
|
TileImage above;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
|
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY)
|
||||||
{
|
{
|
||||||
if (below != null) {
|
if (below != null) {
|
||||||
below.drawTo(gr, destX, destY, srcX, srcY);
|
below.drawWithTimeTo(gr, time, destX, destY, srcX, srcY);
|
||||||
}
|
}
|
||||||
above.drawTo(gr, destX, destY, srcX, srcY);
|
above.drawWithTimeTo(gr, time, destX, destY, srcX, srcY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,9 +63,9 @@ public abstract class TileImage
|
||||||
int offsetY;
|
int offsetY;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
|
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY)
|
||||||
{
|
{
|
||||||
source.drawTo(gr, destX, destY, srcX+offsetX, srcY+offsetY);
|
source.drawWithTimeTo(gr, time, destX, destY, srcX+offsetX, srcY+offsetY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -82,7 +87,7 @@ public abstract class TileImage
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawTo(Graphics2D gr, int destX, int destY, int srcX, int srcY)
|
public void drawWithTimeTo(Graphics2D gr, int time, int destX, int destY, int srcX, int srcY)
|
||||||
{
|
{
|
||||||
srcX = srcX * basisSize / STD_SIZE;
|
srcX = srcX * basisSize / STD_SIZE;
|
||||||
srcY = srcY * basisSize / STD_SIZE;
|
srcY = srcY * basisSize / STD_SIZE;
|
||||||
|
|
Reference in a new issue