새로운 열거 값을 할당, 나는 변수를 생성자에서캔트 내가 열거가과 같이 정의 변수
private Direction direction;
를 할당 :
direction = Direction.Right;
그런 다음, 같은 클래스의 메소드에, 나는 새로운 열거 값을 할당하려고 :
direction = Direction.Down;
하지만 내게 허락하지 않습니다! 올바른 값으로 돌아가는 것은 그것이 설정되는 유일한 장소가 생성자에 있다고 생각하는 것입니다.
무슨 일 이니? 편집
O_O - ... 더 많은 코드namespace MyFirstGame
{
public enum Direction
{
Left,
Right,
Up,
Down
}
}
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MyFirstGame
{
public class Invader : Sprite, IMovable
{
private InvaderType invaderType { get; set; }
private Direction direction;
private Vector2 speed;
public Invader(Texture2D image, Vector2 position)
: base(image, position, new Point(30, 16), new Point(0, 0), new Point(2, 0))
{
direction = Direction.Right;
speed.X += 30;
}
public override void Update(GameTime gameTime, Rectangle clientBounds)
{
timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
if (timeSinceLastFrame > milliSecondsPerFrame)
{
timeSinceLastFrame -= milliSecondsPerFrame;
++currentFrame.X;
if (currentFrame.X >= SheetSize.X)
{
currentFrame.X = 0;
}
Move(direction, clientBounds);
}
}
public void Move(Direction direction, Rectangle clientBounds)
{
if (direction == Direction.Right)
{
//is invader 3 px from the right edge?
//if yes: then drop
//else keep on truckin' to the right!
if (position.X >= (clientBounds.Width - (Image.Width + 3)))
{
//position.X = 0;
position.Y += speed.X;
direction = Direction.Down;
}
else
{
position.X += speed.X; //Speed
}
}
else if (direction == Direction.Down)
{
speed.X *= -1;
position.X += speed.X;
}
}
}
}
방법
'깨끗한 솔루션'을 작성한 다음 '빌드 솔루션'을 작성 했습니까? – Oded
귀하의 질문에 대한 이해를 돕기 위해 더 많은 코드를 게시해야합니다. – vissi
당신이 제안했지만 그래도 똑같습니까? – TheDude