Jump to content
  • Advertisement
Sign in to follow this  
chris2307

Unable to create a new vector

This topic is 2226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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));
}

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!