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

Author Topic: Doesn't draw circles  (Read 1657 times)

0 Members and 1 Guest are viewing this topic.

Elfinity

  • Newbie
  • *
  • Posts: 3
    • View Profile
Doesn't draw circles
« on: March 31, 2011, 07:00:56 pm »
Code: [Select]
int main()
{
sf::RenderWindow WMain(sf::VideoMode(WINDOW_WIDTH,WINDOW_HEIGHT,WINDOW_BPP),"Title");
WMain.SetFramerateLimit(100);
sf::Image IBackGround;
IBackGround.LoadFromFile("C:\\Users\\Administrator\\Documents\\Visual Studio 2008\\Projects\\AsteroidsLG\\Release\\background.png");
sf::Sprite BackGround(IBackGround);BackGround.Resize(WINDOW_WIDTH,WINDOW_HEIGHT);
sf::Shape Hull = sf::Shape::Rectangle(0,0,HULL_W,HULL_H,sf::Color(255,255,0),1);
Hull.Move(300,300);
sf::Shape Weapon = sf::Shape::Line(0,0,WEAPON0_W,WEAPON0_H,WEAPON0_T,sf::Color(255,0,0));
const sf::Input &gInput = WMain.GetInput();
float ElTime = 0;
sf::Clock gClock;
std::vector<sf::Shape *> Balls;
float lastShot = 1;
while(WMain.IsOpened())
{
sf::Event Event;
while(WMain.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
WMain.Close();
}

ElTime = WMain.GetFrameTime();
if(gInput.IsKeyDown(sf::Key::W))
{
Hull.Move(0,ElTime * -100);
}
if(gInput.IsKeyDown(sf::Key::A))
{
Hull.Move(ElTime * -100,0);
}
if(gInput.IsKeyDown(sf::Key::D))
{
Hull.Move(ElTime * 100,0);
}
if(gInput.IsKeyDown(sf::Key::S))
{
Hull.Move(0,ElTime*100);
}
if(gInput.IsKeyDown(sf::Key::Space))
{
lastShot = gClock.GetElapsedTime();
//if(lastShot > 1)
//{
sf::Shape *s = new sf::Shape;//::Circle(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H,
//5,sf::Color(255,255,255),1);
s->Circle(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H,
5,sf::Color(255,255,255),1);
Balls.push_back(s);
//}

}


WMain.Clear(sf::Color(0,220,0));


Weapon.SetPosition(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H);
WMain.Draw(BackGround);
WMain.Draw(Hull);
WMain.Draw(Weapon);
for(int i = 0;i<Balls.size();i++)
{
if(Balls[i]->GetPosition().y < WINDOW_HEIGHT  || Balls[i]->GetPosition().y > 0)
{

Balls[i]->Move(0,ElTime * -150);
WMain.Draw(*(Balls[i]));
//printf("%d \n",Balls.size());
}
else if(Balls[i]->GetPosition().y > WINDOW_HEIGHT || Balls[i]->GetPosition().y < 0)
{
delete Balls[i];
}

}

WMain.Display();
}

return EXIT_SUCCESS;
}

I try to make the shape an vector array so that if its out of the screen it doesn't take memory.But it just doesn't render it.
What could be the problem ?

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Doesn't draw circles
« Reply #1 on: March 31, 2011, 09:29:18 pm »
After a short look, at least one problem is in the following code:

Code: [Select]
sf::Shape *s = new sf::Shape;
s->Circle(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H, 5,sf::Color(255,255,255),1);


You're misusing Circle(). It's a class method (i.e. static class function) that returns a new shape. You should do something like this instead:

Code: [Select]
sf::Shape* s( new sf::Shape( sf::Shape::Circle( ... ) ) );

Please always try to provide a minimal code example that reproduces your problem. It's sometimes exhausting to skip all the irrelevant parts in source code. :)

Elfinity

  • Newbie
  • *
  • Posts: 3
    • View Profile
Doesn't draw circles
« Reply #2 on: March 31, 2011, 10:30:46 pm »
Quote from: "Tank"
After a short look, at least one problem is in the following code:

Code: [Select]
sf::Shape *s = new sf::Shape;
s->Circle(Hull.GetPosition().x+(HULL_W/2),Hull.GetPosition().y - WEAPON0_H, 5,sf::Color(255,255,255),1);


You're misusing Circle(). It's a class method (i.e. static class function) that returns a new shape. You should do something like this instead:

Code: [Select]
sf::Shape* s( new sf::Shape( sf::Shape::Circle( ... ) ) );

Please always try to provide a minimal code example that reproduces your problem. It's sometimes exhausting to skip all the irrelevant parts in source code. :)

I always thought that was the problem but never knew why.
Thanks for the help :)