Unable to create a new vector

Started by
5 comments, last by chris2307 11 years, 7 months ago
Hi all,

I am trying to create some vector objects which will act as stars on the screen to fly past to the left. At the moment, I cannot get this to work. Can anyone see what I am doing wrong? The screen goes black so I think it may be a directX error but when I take out the push_back line, it works fine. The code below is creating an object and moving it. The code underneath that is the star class (All very simple... or I thought).


stars.push_back(star(SCREEN_WIDTH, SCREEN_HEIGHT));
for (std::vector<star>::iterator IT = stars.begin(); IT != stars.end(); IT++)
{
(*IT).move();
}




class star
{
private:
int yPos;
int xPos;
public:
star(int sw, int sh)
{
yPos = sh/2;
xPos = sw;
}
void move()
{
xPos--;
}
int xPosition()
{
return xPos;
}
int yPosition()
{
return yPos;
}
};


Cheers
Advertisement
We'd need to see more code. This tells us nothing about how you're drawing the stars.
Thanks for the reply. This is how I am drawing the image. Obviously, I am creating the texture before anything is executed.

D3DXCreateTextureFromFile(d3dDevice, "star.png", &starSprite);

for(std::vector<star>::iterator IT = stars.begin(); IT != stars.end(); )
{
D3DXVECTOR3 starPosition((*IT).xPosition(), (*IT).yPosition(), 0);
d3dSprite->Draw(starSprite, NULL, &center, &starPosition, D3DCOLOR_XRGB(255, 255, 255));
}

Thanks for the reply. This is how I am drawing the image. Obviously, I am creating the texture before anything is executed.

D3DXCreateTextureFromFile(d3dDevice, "star.png", &starSprite);

for(std::vector<star>::iterator IT = stars.begin(); IT != stars.end(); )
{
D3DXVECTOR3 starPosition((*IT).xPosition(), (*IT).yPosition(), 0);
d3dSprite->Draw(starSprite, NULL, &center, &starPosition, D3DCOLOR_XRGB(255, 255, 255));
}



Where did the increment for IT go?
Don't be scared to show us all your code.
Have you tried stepping through one game loop using your debugger?

Where did the increment for IT go?


Umm... I'm not sure blink.png

Seems to have solved my problem though, putting it back in. Should have noticed that really as I have plenty of other sprites using the same method as I am doing this. Thanks for pointing out what i missed! smile.png

This topic is closed to new replies.

Advertisement