c# - How to move a field left and right without user input, using ints in xna -
well have code: variables:
int x; int maxx = 284; //rectangle rectangle sourcerect; //texture texture2d texture; in update() method:
if (x++ >= maxx) { x--; //to fix x -= 284; } and draw() method:
spritebatch.draw(texture, new vector2(263 + x, 554), sourcerect, color.white, 0f, origin, 1.0f, spriteeffects.none, 0); //i have properties not important so want move field horizontaly these ints, moves right point 1 point 2 , blinks point 1 , on here's desired output:
[ output: ] [ ] [<1>field <2>] [ ] so field @ point 1. want move point 2, this:
[<1>field---------------><2>] and then, when reaches point 2:
[<1><---------------field<2>] and loop this. point 1 point 2 , point 1 , point 2 again. total distance between points 284 pixels (points part of background image). know it's decrementing integer how it?
i'm not quite sure you're trying explain think want have point move right until hits max point, start moving left until hits min point.
one solution add direction bool e.g.
bool movingright = true; int minx = 263; update()
if( movingright ) { if( x+1 > maxx ) { movingright = false; x--; } else x++; } else { if( x-1 < minx ) { movingright = true; x++; } else x--; }
Comments
Post a Comment