Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

101 Neutral

About GRMaverick

  • Rank
  1. GRMaverick

    Drawing Multiple Sprites (projectiles)

    Is "Projectile newProjectile()" a class or a structure. Because my "Projectile" is a structure, I'm not sure you can have constructors for structures, no?   // now add it to the projectiles list   ProjectilesList.push_back(newProjectile);     // finally, tell the player you just shot a projectile   _player->ProjectileFire(); }   // Also in the Update() code, loop through all projectiles, see if they hit an enemy, or if they went off the screen, and remove them from the list ...   // Later, in your Draw() function, loop through the projectiles, drawing everything for (int i = 0; i < ProjectilesList.size(); ++i) {   ProjectileList.Draw(); }     Would I initialise the variables and content within the projectile structure then? 
  2. GRMaverick

    Drawing Multiple Sprites (projectiles)

      How would you go about using std::vector. I've heard of it but never used it or seen it implemented.
  3. GRMaverick

    Drawing Multiple Sprites (projectiles)

      The image used is supposed to be the same and they are supposed to be drawn from the same position. It's just when I press the spacebar, they all draw at the same time :-( I need them to draw one at a time.
  4. GRMaverick

    Drawing Multiple Sprites (projectiles)

    I highly doubt anything will work at all with this kind of code. This makes absolutely no sense. You create new pointers, and then you change them to something else immediately (which is also a memory leak and a crash if you ever actually attempted to free this memory). All 5 bullets are pointing to the same texture and boundary. Very clearly they will all be drawn in the same spot. If they aren’t, you have another bug (hint: don’t mix updating and rendering as you are doing now).   Why are you setting i to 0? L. Spiro     It made no sense because I missed a bit of code out where I was assigning a Texture2D-Load("", false) to a variable and then assign that to the bit inside the loop. According to my lecturer it was more efficient.  I was setting i=0 so that it would re-iterate through the loop after the loop had reached PROJECTILES.
  5. GRMaverick

    Drawing Multiple Sprites (projectiles)

      How do you 'remove' from an array. I know you can remove from an List but not from an Array.
  6. Hi,   I'm trying to create more than one projectile in an array because using when using one projectile, when you fire a second time, the first projectile disappears for the projectile to fire again.  I thought using for-loops would the best way to go about it but not sure what I am doing wrong. //Here is instantiating the class for (int i = 0; i < PROJECTILES; i++) { _projectile[i] = new Projectile(); } //Projectile Inits for (int i = 0; i < PROJECTILES; i++) { _projectile[i]->_speed = 0.8f; _projectile[i]->_frameTime = 250; _projectile[i]->_launched = false; } //Loading Projectile Content for (int i = 0; i < PROJECTILES; i++) { _projectile[i]->_texture = new Texture2D(); _projectile[i]->_boundry = new Rect(); _projectile[i]->_texture = projTexture; _projectile[i]->_boundry = projRect; } //Spacebar to fire for (int i = 0; i < PROJECTILES; i++) { if (state->IsKeyDown(Input::Keys::SPACE)) { _projectile[i]->_boundry->X = _player->_position->X + 35; _projectile[i]->_boundry->Y = _player->_position->Y + 59; _projectile[i]->_launched = true; } if (i == 5) { i = 0; } } /?Draw Projectile for (int i = 0; i < PROJECTILES; i++) { if (_projectile[i]->_launched) { SpriteBatch::Draw(_projectile[i]->_texture, _projectile[i]->_boundry, 0.5f, 0.0f); _projectile[i]->_boundry->Y -= _projectile[i]->_speed * elapsedTime; } } Now the issue I'm having is that PROJECTILES = 5 so it draws all five projectiles at the same time below each other, and when fired the all move together. The speed is also stacking so the five projectiles move faster than the 1 projectile should be moving at.   Not sure what mistakes I am making and I'm not sure if I have given enough information.  Thank you   Ryan
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!