到目前为止,我有一个跳跃动画。它使用一个整数“跳转”循环通过一个图像数组创建一个跳转动画,另外,取决于哪个数字“跳转”,高度"PositionY“将增加或减少,当跳转击中10,动画结束……这是跳转动画代码
public Bitmap Jump_Frame2Draw()
{
Jump_Frames = new Bitmap[] { Jump_1, Jump_2, Jump_3, Jump_4, Jump_5, Jump_6, Jump_7,Jump_7,
Jump_8, Jump_8 };
if (jump < Jump_Frames.Length)
{
if (jump <= 3)
{
PositionY -= 30;
}
else if (jump == 8 || jump == 10)
{
PositionY += 0;
}
else
{
PositionY += 24;
}
jumpFrame = Jump_Frames[jump];
jump++;
if (jump == 10)
{
jumpTimer.Stop();
isJumping = false;
jump = 0;
standTimer.Start();
Invalidate();
}
}
tracer = jumpFrame.GetPixel(1, 1);
jumpFrame.MakeTransparent(tracer);
isJumping = true;
return jumpFrame;
}通过使用计时器和画图事件,我可以每隔x秒简单地调用这个方法,以便在我按指定的跳转键时绘制它.现在我的问题是,让我说我处于跳跃式动画的中间,我想回到.How --我做了什么--我做了。把它想象成一次双重跳跃。此外,跳跃和身高(PositionY)是直接相关的。因此,如果跳跃是0,1,2或3,那么高度是214 -(跳跃+ 1) * 30)。否则,如果跳跃是(5-9)高度是94 +(跳跃- 4) * 24)。因此,任何图像绘制的最大高度是94。(它的窗口形式是向下的,向下的是向上的。)(0,0)位于左上角)。
/
对于视觉视角,这类似于我的跳转动画。这个时间稍微短一点,但这是我能找到的最好的了。
跳转动画:https://media.giphy.com/media/wXervlFEqohO0/giphy.gif
想象一下这家伙是个铁人,他用他的喷气式助推器跳起来,但现在,当他还在空中的时候,他决定直接上去。
发布于 2017-05-29 12:54:16
我认为,如果将大多数特定于动画的代码移到专用的JumpAnimation类中,您会省去很多麻烦。在构造函数中传递特定动画所需的所有信息:
class JumpAnimation
{
public JumpAnimation(int howHigh)
{
...
}
}响应在空格键上的点击,您知道您必须创建一个JumpAnimation。但是当你的计时器在滴答作响时,你不想处理跳转或jetpack动画的细节--你想要一个IAnimation界面,它允许你继续动画,不管它是什么。当您使用jetpack时,您只想用JetPackAnimation替换当前活动的任何动画。
以你的形式:
private IAnimation currentAnimation = null;和IAnimation接口:
public interface IAnimation
{
// get the bitmap at the time relevant to the animation start
Bitmap GetBitmapAt(int time);
}当您在IAnimation中实现JumpAnimation时,您可以重用您在问题中共享的大量代码。
现在,不只是返回Bitmap,您可以创建一个类,它包含有关“动画中的当前步骤”的更多信息:
public class AnimationStep
{
public Bitmap Bitmap { get; set; }
// the y-offset
public int OffsetY { get; set; }
// indicates whether this was the last step of the animation
public bool Completed { get; set; }
// a jump animation can be interrupted by a jetpack animation, but a DieAnimation cant:
public bool CanBeInterrupted { get; set; }
...
}我希望你明白这个想法。我并不是说这是解决你问题的唯一或最好的方法,但有时另一个人对这件事的看法会帮助你跳出框框思考。
https://stackoverflow.com/questions/44242114
复制相似问题