syntax - Cant assign new enum value to variable -
i have enum defined so:
public enum direction { left, right, up, down }
and following variable in class:
private direction direction;
in constructor, assign variable:
direction = direction.right;
then, in method in same class, try assign new enum value:
direction = direction.down;
but won't let me! keeps going right value thought place gets set in constructor!
what's going on? o_o
edit - more code
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 right edge? //if yes: drop //else keep on truckin' 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; } } } }
the method
assuming don't have stale binaries (as pointed out oded)...
set breakpoint on assignment, , make sure executes. then, after assignment (use step over
), verify value of direction
.
if it's correct @ point, something else causing reset.
Comments
Post a Comment