2 Replies - 550 Views - Last Post: 17 September 2012 - 08:37 AM

#1 Goldfinger007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 17-September 12

Animation looks sometimes distorted

Posted 17 September 2012 - 08:12 AM

I have 4 different animation methods. Two of them work fine, but the other two methods(vorrück, rückvor) don't work correctly. The size of the animation is different when I use the vorrück and rückvor methods. I want that they have the same size as vorwärts and rückwärts. The animations of "vorrück" and "rückvor" are a little distorted.
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

Is This A Good Question/Topic? 0
  • +

Replies To: Animation looks sometimes distorted

#2 Curtis Rutland  Icon User is offline

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 4527
  • View blog
  • Posts: 7,898
  • Joined: 08-June 10

Re: Animation looks sometimes distorted

Posted 17 September 2012 - 08:36 AM

Is this XNA?
Was This Post Helpful? 0
  • +
  • -

#3 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Animation looks sometimes distorted

Posted 17 September 2012 - 08:37 AM

I see an instance of the Texture2D class, so this is definitely XNA. I'll throw it over to that section.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1