Hello Guest

Author Topic: animation while moving diagonally?  (Read 2069 times)

0 Members and 1 Guest are viewing this topic.

Commanderstitch

  • Member
  • Posts: 36
  • Personal Text
    • View Profile
    • commanderstitch Homepage (coming someday)
animation while moving diagonally?
« on: June 17, 2015, 06:50:16 PM »
If anyone has insight on this it would be cool.

what i want:
when you are moving diagonally you have an animated sprite. (so it's not ghosting everywhere)
currently you move diagonally but you don't have animated sprite.
i can detect when i'm clicking both movement buttons together, it even sets my diag movement to true and it moves past the stop animations, but for some reason the animations stop anyway.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Otter;
using OtterAdventure.Entities.objects;
 
namespace OtterAdventure.Entities
{
    class Player : Entity
    {
        private Spritemap<string> sprite;
 
        public int moveSpeed = 2;//was 4.0f
 
        public int direction = 0;
        bool hMove = true;
        bool vMove = true;
        bool dMove = false;
 
        public Player(float x = 0, float y = 0)
        {
            X = x;
            Y = y;
            sprite = new Spritemap<string>(Assets.PLAYER, 46, 56);
            addNewSprites();
            sprite.Play("standDown");
            Graphic = sprite;
        }
 
        public override void Update()
        {
            base.Update();
            Console.WriteLine("curAnim: " + sprite.CurrentAnim);
            Console.WriteLine("curFrame: " + sprite.CurrentFrame);
            Console.WriteLine("curFrameIndex: " + sprite.CurrentFrameIndex);
            Console.WriteLine("hmove: " + hMove + " vmove: " + vMove + " dMove: " + dMove);
            //Console.WriteLine("r: " + r + "l: " + l + "u: " + u + "d: " + d + "ul: " + ul + "ur: " + ur + "dl: " + dl + "dr: " + dr);
 
            if (Global.PlayerSession.Controller.Button("A").Down || Global.PlayerSession.Controller.Button("LEFT").Down)//left
            {
                X -= moveSpeed;
                sprite.Play("walkLeft");
                direction = Global.D_LEFT;
                hMove = true;
                //sprite.FlippedX = true; cool i can do this. :D
            }
            else if (Global.PlayerSession.Controller.Button("D").Down || Global.PlayerSession.Controller.Button("RIGHT").Down)//right
            {
                X += moveSpeed;
                sprite.Play("walkRight");
                direction = Global.D_RIGHT;
                hMove = true;
                //sprite.FlippedX = false; cool i can do this. :D
            }
            else
            {
                hMove = false;
            }
            if (Global.PlayerSession.Controller.Button("W").Down || Global.PlayerSession.Controller.Button("UP").Down)//up
            {
                Y -= moveSpeed;
                sprite.Play("walkUp");
                direction = Global.D_UP;
                vMove = true;
                //sprite.FlippedX = false;
            }
            else if (Global.PlayerSession.Controller.Button("S").Down || Global.PlayerSession.Controller.Button("DOWN").Down)//down
            {
                Y += moveSpeed;
                sprite.Play("walkDown");
                direction = Global.D_DOWN;
                vMove = true;
                //sprite.FlippedX = false;
            }
            else
            {
                vMove = false;
            }
            if (((Global.PlayerSession.Controller.Button("A").Down || Global.PlayerSession.Controller.Button("LEFT").Down)
                && (Global.PlayerSession.Controller.Button("W").Down || Global.PlayerSession.Controller.Button("UP").Down))//left and up
                || ((Global.PlayerSession.Controller.Button("D").Down || Global.PlayerSession.Controller.Button("RIGHT").Down)
                    && (Global.PlayerSession.Controller.Button("W").Down || Global.PlayerSession.Controller.Button("UP").Down))//right and up
                    || ((Global.PlayerSession.Controller.Button("A").Down || Global.PlayerSession.Controller.Button("LEFT").Down)
                        && (Global.PlayerSession.Controller.Button("S").Down || Global.PlayerSession.Controller.Button("DOWN").Down))//left and down
                        || ((Global.PlayerSession.Controller.Button("D").Down || Global.PlayerSession.Controller.Button("RIGHT").Down)
                           && (Global.PlayerSession.Controller.Button("S").Down || Global.PlayerSession.Controller.Button("DOWN").Down)))//right and down
            {
                Console.WriteLine("you are pressing 2 buttons at once");
                dMove = true;
                Console.WriteLine("see? " + dMove);
            }
            else
            {
                dMove = false;
            }
            stopWalkingAnimations();
            //FIRE
            if (Global.PlayerSession.Controller.Button("X").Pressed || Global.PlayerSession.Controller.Button("RControl").Pressed)
            {
                Global.GAME.Scene.Add(new Bullet(X, Y, direction));//is this going to be tied to that screen only? :/ probably.
            }
        }
 
        public void addNewSprites()
        {
            sprite.Add("standLeft", new int[] { 24 });
            sprite.Add("standRight", new int[] { 16 });
            sprite.Add("standUp", new int[] { 8 });
            sprite.Add("standDown", new int[] { 0 });
            sprite.Add("walkRight", new int[] { 16, 17, 18, 19 }, new float[] { 10f, 10f });
            sprite.Add("walkLeft", new int[] { 24, 25, 26, 27 }, new float[] { 10f, 10f });
            sprite.Add("walkUp", new int[] { 8, 9, 10, 9 }, new float[] { 10f, 10f });
            sprite.Add("walkDown", new int[] { 0, 1, 2, 1 }, new float[] { 10f, 10f });
        }
        public void stopWalkingAnimations()
        {
            if (!hMove && !vMove && !dMove)
            {
                switch (sprite.CurrentAnim)
                {
                    case ("walkLeft"):
                        sprite.Play("standLeft");
                        break;
                    case ("walkRight"):
                        sprite.Play("standRight");
                        break;
                    case ("walkUp"):
                        sprite.Play("standUp");
                        break;
                    case ("walkDown"):
                        sprite.Play("standDown");
                        break;
 
                }
            }
        }
    }
}
- Commanderstitch

Commanderstitch

  • Member
  • Posts: 36
  • Personal Text
    • View Profile
    • commanderstitch Homepage (coming someday)
Re: animation while moving diagonally?
« Reply #1 on: June 17, 2015, 10:57:02 PM »
K, the problem was that i was having the two animations conflict with each other, both were trying to play at the same time, so if i clicked up and left, both animations would try to play at teh same time resulting in neither playing. All i had to do then was exclude one of them from playing if the other one was being pressed. :-)
- Commanderstitch