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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Elfinity

Pages: [1]
1
General / Doesn't draw circles
« 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 :)

2
General / 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 ?

3
General / Pivot point
« on: March 25, 2011, 07:22:55 pm »


Uploaded with ImageShack.us
Code: [Select]
sf::Vector2f mTP = sf::Vector2f(WMain.GetInput().GetMouseX()-tTurrTankS.GetPosition().x,WMain.GetInput().GetMouseY()-tTurrTankS.GetPosition().y);
float fAngle = atan(mTP.x/mTP.y);
if(mTP.x == 0 && mTP.y == 0)
fAngle = 0;
fAngle *= 180/3.14159;
if(mTP.y >= 0)
fAngle += 180;

tTurrTankS.SetRotation(fAngle);

This is the code I use but,the Turrent rotates like it's center is somewhere else.

Pages: [1]
anything