Sign in to follow this  
chris2307

Unable to create a new vector

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).

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

[code]

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;
}
};
[/code]

Cheers

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.
[code]
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));
}
[/code]

Share this post


Link to post
Share on other sites
[quote name='chris2307' timestamp='1347490551' post='4979503']
Thanks for the reply. This is how I am drawing the image. Obviously, I am creating the texture before anything is executed.
[code]
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));
}
[/code]
[/quote]

Where did the increment for IT go?

Share this post


Link to post
Share on other sites
[quote name='alvaro' timestamp='1347491354' post='4979506']
Where did the increment for IT go?
[/quote]

Umm... I'm not sure [img]http://public.gamedev.net//public/style_emoticons/default/blink.png[/img]

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! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this