c# - Getting sprites to move on their own in XNA -
in code, attempting move 3 sprites on x axis @ 1 direction , speed. however, when wrote code in class, compiled fine without errors, when game started, sprites wanted move not move @ all. sit there. code below:
class enemy : enemysprite { const string enemy_assetname = "badguyleft"; const int start_position_x1 = 350; const int start_position_x2 = 600; const int start_position_x3 = 750; const int start_position_y = 415; const int move_left = -1; int wizardspeed = 160; enum state { walking }
the real issue below:
public void loadcontent(contentmanager thecontentmanager) { base.loadcontent(thecontentmanager, enemy_assetname); } public void update(gametime thegametime) { //keyboardstate acurrentkeyboardstate = keyboard.getstate(); //updatemovement(acurrentkeyboardstate); //mpreviouskeyboardstate = acurrentkeyboardstate; position[0] = new vector2(start_position_x1, start_position_y); position[1] = new vector2(start_position_x2, start_position_y); position[2] = new vector2(start_position_x3, start_position_y); base.update(thegametime, mspeed, mdirection); } private void updatemovement(keyboardstate acurrentkeyboardstate) { //int positiontracker = start_position_x3; if (mcurrentstate == state.walking) { mspeed = vector2.zero; mdirection = vector2.zero; (int = 0; < position.count(); i++) if (mcurrentstate == state.walking) { mspeed.x = wizardspeed; mdirection.x = move_left; } }
you never changing position of sprite.
you're update method movement should (typically) take place.
it this:
//this move object left vector2 speed = new vector2(-10, 0); public void update(gametime thegametime) { //this add speed of sprite position //making move position[0] += speed; position[1] += speed; position[2] += speed; base.update(thegametime, mspeed, mdirection); }
Comments
Post a Comment