Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

Unable to create a new vector


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 chris2307   Members   -  Reputation: 163

Like
0Likes
Like

Posted 12 September 2012 - 03:29 PM

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

Sponsor:

#2 FLeBlanc   Members   -  Reputation: 2024

Like
0Likes
Like

Posted 12 September 2012 - 03:36 PM

We'd need to see more code. This tells us nothing about how you're drawing the stars.

#3 chris2307   Members   -  Reputation: 163

Like
0Likes
Like

Posted 12 September 2012 - 04:55 PM

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));
}


#4 Álvaro   Members   -  Reputation: 6183

Like
1Likes
Like

Posted 12 September 2012 - 05:09 PM

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?

#5 kd7tck   Members   -  Reputation: 608

Like
-1Likes
Like

Posted 12 September 2012 - 09:18 PM

Don't be scared to show us all your code.

#6 rip-off   Moderators   -  Reputation: 5305

Like
0Likes
Like

Posted 13 September 2012 - 01:46 AM

Have you tried stepping through one game loop using your debugger?

#7 chris2307   Members   -  Reputation: 163

Like
0Likes
Like

Posted 15 September 2012 - 12:34 PM

Where did the increment for IT go?


Umm... I'm not sure Posted Image

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! Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS