I get no error message, but their is something wrong with the vorrück and rückvor methods.
Animation class:
class Animation{
private int _animIndex;
public enum Animationsablaeufe
{
vorwärts, rückwärts, vorrück, rückvor
}
private void vorwärts(List<Rectangle> sourceRects, int framewidth, int frameheight)
{
for (int i = 0; i < sourceRects.Capacity; i++)
sourceRects.Add(new Rectangle(i * framewidth, 0, framewidth, frameheight));
}
private void rückwärts(List<Rectangle> sourceRects, int framewidth, int frameheight)
{
for (int i = 0; i < sourceRects.Capacity; i++)
sourceRects.Add(new Rectangle((sourceRects.Capacity - 1 - i) * framewidth, 0, framewidth, frameheight));
}
private void vorrück(List<Rectangle> sourceRects, int framewidth, int frameheight)
{
sourceRects.Capacity = sourceRects.Capacity * 2;
for (int i = 0; i < sourceRects.Capacity /2; i++)
sourceRects.Add(new Rectangle(i * framewidth, 0, framewidth, frameheight));
for (int i = 0; i < sourceRects.Capacity /2; i++)
sourceRects.Add(new Rectangle((sourceRects.Capacity /2 - 1 - i) * framewidth, 0, framewidth, frameheight));
}
private void rückvor(List<Rectangle> sourceRects, int framewidth, int frameheight)
{
sourceRects.Capacity = sourceRects.Capacity * 2;
for (int i = 0; i < sourceRects.Capacity /2; i++)
sourceRects.Add(new Rectangle((sourceRects.Capacity /2 - 1 - i) * framewidth, 0, framewidth, frameheight));
for (int i = 0; i < sourceRects.Capacity /2; i++)
sourceRects.Add(new Rectangle(i * framewidth, 0, framewidth, frameheight));
}
public TimeSpan PassedTime { get; private set; }
public List<Rectangle> SourceRects { get; private set; }
public Texture2D Texture {get; private set; }
public TimeSpan Duration { get; private set; }
public Animationsablaeufe Ablauf { get; private set; }
public Animation(List<Rectangle> sourceRects, Texture2D texture, TimeSpan duration, Animationsablaeufe animationsablaeufe)
{
int framewidth = texture.Width / sourceRects.Capacity;
int frameheight = texture.Height;
switch (animationsablaeufe)
{
case Animationsablaeufe.vorwärts:
{
vorwärts(sourceRects,framewidth,frameheight);
break;
}
case Animationsablaeufe.rückwärts:
{
rückwärts(sourceRects, framewidth, frameheight);
break;
}
case Animationsablaeufe.vorrück:
{
vorrück(sourceRects, framewidth, frameheight);
break;
}
case Animationsablaeufe.rückvor:
{
rückvor(sourceRects, framewidth, frameheight);
break;
}
}
SourceRects = sourceRects;
Texture = texture;
Duration = duration;
Ablauf = animationsablaeufe;}
public void Update(GameTime dt)
{
PassedTime += dt.ElapsedGameTime;
if (PassedTime > Duration)
{
PassedTime -= Duration; // zurücksetzen
}
var percent = PassedTime.TotalSeconds / Duration.TotalSeconds;
_animIndex = (int)Math.Round(percent * (SourceRects.Capacity - 1));
}
public void Draw(SpriteBatch batch)
{
batch.Draw(Texture, new Rectangle(0, 0, Texture.Width / SourceRects.Capacity, Texture.Height), SourceRects[_animIndex], Color.White);
}
I added my entire project. So you can see that something is wrong with the animation.
I forgot the link to my project: http://www.file-uplo...Game26.rar.html

New Topic/Question
Reply


MultiQuote






|