Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best way to draw projectiles ? [SOLVED]  (Read 2597 times)

0 Members and 1 Guest are viewing this topic.

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
Best way to draw projectiles ? [SOLVED]
« on: October 19, 2012, 10:43:17 pm »
Im making a game like space invaders, you fly a spaceship and destroy enemies. I got the player spaceship loading and displaying and moving. Now i want to make projectiles, but i cant get it to work, how should i do it ?
projectiles from your spaceship obviously.

I tried something but kinda failed:

Inside of a class:

static sf::Texture _projectileTexture;
static sf::Sprite _projectileSprite[30];

inside of a .cpp

_projectileTexture.loadFromFile("projectile1.png");
for(int n = 0; n < 30; n++)
      _projectileSprite[n].setTexture(_projectileTexture);

for(int n = 0; n < curProjectile;  n++)
       gameWindow.draw(_projectileSprite[n]);

how i try to make new projectiles:

if(inProjectile == true)
{
        curProjectile ++;
        pProjectile[curProjectile];
        _projectileSprite[curProjectile].setPosition(pProjectile[curProjectile].posX, pProjectile[curProjectile].posY);
        return;
}

General declarations:

int curProjectile = -1;

struct Projectile
{
        float posX;
        float posY;
        bool alive;
};
Projectile *pProjectile = new Projectile[30];

running in main so i can initialize

for(int n(0); n < 30; n++)
{
        pProjectile[n].posX = 20;
        pProjectile[n].posY = 20;
}
 

suggestions please :D


Let me explain here what i did:

1. Load the projectile .png into a texture.
2. Load the texture into 30 sprite projectiles. (hoping that it will be enough)
3. Create with the Struct 30 projectiles.
4. Create/Set position of each one as they get shot.
« Last Edit: October 20, 2012, 12:49:43 pm by OutlawLee »

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Best way to draw projectiles ?
« Reply #1 on: October 20, 2012, 12:21:59 am »
Please discribe more precise what you want to achieve. Also what exactly failed in your code?

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
Re: Best way to draw projectiles ?
« Reply #2 on: October 20, 2012, 10:44:15 am »
I want to shoot with my ship.
They are not displaying, and i dont know if this is a efficient method to make new projectiles.
« Last Edit: October 20, 2012, 11:14:49 am by OutlawLee »

OutlawLee

  • Jr. Member
  • **
  • Posts: 50
  • This is my personal text. Dont read it.
    • View Profile
    • Email
Re: Best way to draw projectiles ?
« Reply #3 on: October 20, 2012, 12:49:28 pm »
FIXED.