我有一个bool叫attack我Q按下按钮时设置为true (Q是攻击)
我用断点试图自己解决问题.设置attack为true 的代码行正在运行,但实际上并没有设置attack为true ...我是XNA的新手,很抱歉,如果这是一个明显的解决方案.这是代码.. :( ps我遗漏了很多与问题无关的代码)
public class Player
{
Animation playerAnimation = new Animation();
public void Update(GameTime gameTime)
{
keyState = Keyboard.GetState()
if (keyState.IsKeyDown(Keys.Q))
{
tempCurrentFrame.Y = 0;
*** playerAnimation.Attack = true; *** This line of code runs yet doesn't actually work
}
public class Animation
{
bool attack;
public bool Attack
{
get { return attack; }
set { value = attack; }
}
public void Update(GameTime gameTime)
{
if (active)
frameCounter += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
else
frameCounter = 0;
if (attack) ***This never turns true***
switchFrame = 50;
Run Code Online (Sandbox Code Playgroud)
就像我之前说过的那样,我已经使用了断点进行检查,并且所有代码都运行了,我的攻击变量没有任何反应,我不知道为什么不行.
我有一个类似的bool,名为active,所有相同的属性和代码链接,但bool确实更新,这就是为什么我这么卡住.
感谢您的时间.
set存取器中的逻辑是向后的.您需要将字段分配给attacksetter的值,而不是相反
set { attack = value; }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
140 次 |
| 最近记录: |