コード例 #1
0
ファイル: Camera.cs プロジェクト: Killiann/UTDG
        public void SetPosition(Vector2 newPosition)
        {
            position.Y = newPosition.Y;
            //xpos
            if ((newPosition.X - (viewportWidth / 2 / scale)) > 0 &&
                newPosition.X + (viewportWidth / 2 / scale) < map.GetWidth())
            {
                position.X = newPosition.X;
            }
            else
            {
                if ((newPosition.X - (viewportWidth / 2 / scale)) < 0)
                {
                    position.X = viewportWidth / 2 / scale;
                }
                else if (newPosition.X + (viewportWidth / 2 / scale) > map.GetWidth())
                {
                    position.X = map.GetWidth() - viewportWidth / 2 / scale;
                }
            }

            //ypos
            if ((newPosition.Y - (viewportHeight / 2 / scale)) > 0 &&
                newPosition.Y + (viewportHeight / 2 / scale) < map.GetHeight())
            {
                position.Y = newPosition.Y;
            }
            else
            {
                if ((newPosition.Y - (viewportHeight / 2 / scale)) < 0)
                {
                    position.Y = viewportHeight / 2 / scale;
                }
                else if (newPosition.Y + (viewportHeight / 2 / scale) > map.GetHeight())
                {
                    position.Y = map.GetHeight() - viewportHeight / 2 / scale;
                }
            }
        }
コード例 #2
0
 public virtual bool IsOutOfMap()
 {
     return(bounds.X < 0 || bounds.X > map.GetWidth() || bounds.Y < 0 || bounds.Y > map.GetHeight());
 }