I have a bool called attack which I set to true whenever the Q button is pressed (Q is an attack)
I've used breakpoints to try and solve the problem myself. The line of code which sets attack to true is running, but it doesn't actually set attack to true... I'm new to XNA so sorry if this is an obvious solve. Here is the code..: (p.s. I've left out lots of code which has nothing to do with the problem)
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;
Like I said earlier, I've used breakpoints to check, and ALL the code does run, just nothing happens to my attack variable and I'm not sure why not.
I have a similar bool called active with all the same properties and code linked, yet that bool does get updated which is why I am so stuck.
Thank you for your time.
The logic in the set accessor is backwards. You need to assign the field attack to the value of the setter, not the other way around
set { attack = value; }
The problem is
set { value = attack; }
You're setting the value to the field, instead of the field to the value. Change it to
set { attack = value; }
Read the documentation for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With