예제 #1
0
        public override void Update(GameTime gameTime, ref Animation a)
        {
            currentFrame = a.CurrentFrame;
            if (a.IsActive) //isActive is set when player presses down input key to move for example
            {
                frameCounter += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
                if (frameCounter >= switchFrame) //every 100 milliseconds switch frame
                {
                    frameCounter = 0;
                    currentFrame.X++; //if animations are positioned in image according to x axis - then switch to next frame

                    if (currentFrame.X * FrameWidth >= a.Image.Width)
                    {
                        currentFrame.X = 0;
                    }
                }
            }
            else
            {
                frameCounter = 0;
                currentFrame.X = 1;
            }
            a.CurrentFrame = currentFrame;
            a.SourceRect = new Rectangle((int)currentFrame.X * FrameWidth, (int)currentFrame.Y * FrameHeight, FrameWidth, FrameHeight);
        }
예제 #2
0
        public void SetTile(State state, Motion motion, Vector2 position, Texture2D tileSheet, Rectangle tileArea)
        {
            this.state = state;
            this.motion = motion;
            this.position = position;
            increase = true;

            tileImage = CropImage(tileSheet, tileArea);
            range = 50;
            counter = 0;
            moveSpeed = 100f;
            animation = new Animation();
            animation.LoadContent(ScreenManager.Instance.Content, tileImage, "", position);
        }
예제 #3
0
        public override void Update(GameTime gameTime, ref Animation a)
        {
            if (a.IsActive)
            {
                if (!stopUpdating)
                {
                    if (!increase)
                    {
                        a.Alpha -= fadeSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        a.Alpha += fadeSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    if (a.Alpha <= 0.0f) //alpha is from 0 to 1 instead of 0 to 255
                    {
                        a.Alpha = 0.0f;
                        increase = true;
                    }
                    else if (a.Alpha >= 1.0f) //1 is opaque and 0 is transparent
                    {
                        a.Alpha = 1.0f;
                        increase = false;
                    }
                }

                if (a.Alpha == activateValue)
                {
                    stopUpdating = true;
                    timer -= gameTime.ElapsedGameTime;
                    if (timer.TotalSeconds <= 0) //delay for fading right in after fading out (nicer transition)
                    {
                        timer = defaultTime;
                        stopUpdating = false;
                    }
                }
            }
            else
            {
                a.Alpha = defaultAlpha; //if fading isn't active
                stopUpdating = false;
            }
        }
예제 #4
0
        public override void LoadContent(ContentManager content, InputManager input)
        {
            base.LoadContent(content, input);
            fileManager = new FileManager();
            moveAnimation = new Animation();
            Vector2 tempFrames = Vector2.Zero;
            moveSpeed = 100f;

            fileManager.LoadContent("Load/Player.txt", attributes, contents);

            for (int i = 0; i < attributes.Count; i++)
            {
                for (int j = 0; j < attributes[i].Count; j++)
                {
                    switch (attributes[i][j])
                    {
                        case "Health":
                            health = int.Parse(contents[i][j]);
                            break;
                        case "Frames":
                            string[] frames = contents[i][j].Split(' ');
                            tempFrames = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                            break;
                        case "Image":
                            image = this.content.Load<Texture2D>(contents[i][j]);
                            break;
                        case "Position":
                            frames = contents[i][j].Split(' ');
                            position = new Vector2(int.Parse(frames[0]), int.Parse(frames[1]));
                            break;
                    }
                }
            }

            moveAnimation.Frames = new Vector2(3, 4);
            moveAnimation.LoadContent(content, image, "", position);
        }
예제 #5
0
 public virtual void Update(GameTime gameTime, ref Animation a)
 {
 }