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

Author Topic: Problem with circles coordinates  (Read 4122 times)

0 Members and 1 Guest are viewing this topic.

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Problem with circles coordinates
« on: June 08, 2010, 03:29:56 pm »
Why does the following code place circles at only one value of X?
Thanks
Warren

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
    {
int x, y, radius = 20;
 
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1400, 900, 32), "Warren Graphics");

// Clear screen
App.Clear(sf::Color(128, 128, 128));

    // Start game loop
    while (App.IsOpened())
        {
// Process events
        sf::Event Event;

        while (App.GetEvent(Event))
            {
for(x = 0; x < 1400; x = x + 25);
   {
for(y = 0; y < 900; y = y + 25)
        {
App.Draw(sf::Shape::Circle(x, y,radius,sf::Color(255,0,0)));

        // Display window contents on screen
    App.Display();

    // Close window : exit
    if (Event.Type == sf::Event::Closed)
App.Close();

    //Escape key exit
    if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
        }
    }
}
    }
    return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with circles coordinates
« Reply #1 on: June 08, 2010, 03:59:39 pm »
Your update/display code shouldn't be located in the event loop. Look at the tutorials and sample codes to see what a typical game loop should look like.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Problem with circles coordinates
« Reply #2 on: June 08, 2010, 03:59:52 pm »
Hi you should use the [code] tags

BTW, I'm not sure what you mean, but I think your problem is that you need to App.draw for every circle (which for management often means a loop to draw everything in a vector or an array).

If you just want to move one circle you need to define your position coords outside your loop.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with circles coordinates
« Reply #3 on: June 08, 2010, 04:02:51 pm »
Quote
BTW, I'm not sure what you mean, but I think your problem is that you need to App.draw for every circle (which for management often means a loop to draw everything in a vector or an array).

His drawing code is ok, he doesn't need to store the circles.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Problem with circles coordinates
« Reply #4 on: June 08, 2010, 04:06:10 pm »
Quote from: "Laurent"
Quote
BTW, I'm not sure what you mean, but I think your problem is that you need to App.draw for every circle (which for management often means a loop to draw everything in a vector or an array).

His drawing code is ok, he doesn't need to store the circles.


Oh yeah, I guess that's right if you just want circles floating around you can't move.

I'm curious, how are the circles stored? Are they just like pixels on the buffer that get wiped on the next clear and are gone forever?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with circles coordinates
« Reply #5 on: June 08, 2010, 04:14:29 pm »
Quote
I'm curious, how are the circles stored? Are they just like pixels on the buffer that get wiped on the next clear and are gone forever?

Yes. A temporary sf::Shape object is created, its pixels are drawn to the back buffer, and it is destroyed immediately after that. Only the written pixels remain, until they are overwritten by Draw or Clear.
Laurent Gomila - SFML developer

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Problem with circles coordinates
« Reply #6 on: June 08, 2010, 10:23:53 pm »
Mr Gomila
I moved the do loop out of the event loop as I understood you to mean but The results are the same.
Warren

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Problem with circles coordinates
« Reply #7 on: June 08, 2010, 10:25:53 pm »
Revised code
Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
int x, y, radius = 20;

    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(1400, 900, 32), "Warren Graphics");

// Clear screen
App.Clear(sf::Color(128, 128, 128));

for(x = 0; x < 1400; x = x + 25);
{
for(y = 0; y < 900; y = y + 25)
{
App.Draw(sf::Shape::Circle(x, y,radius,sf::Color(255,0,0)));

// Display window contents on screen
App.Display();

}
}

    // Start game loop
    while (App.IsOpened())
{
// Process events
        sf::Event Event;

        while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();

//Escape key exit
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();


}
    }
    return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Problem with circles coordinates
« Reply #8 on: June 08, 2010, 10:54:01 pm »
Your code is still wrong. There are thousands of example on this website, really, you just need to copy and paste ;)

Look at the tutorials for example...
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Problem with circles coordinates
« Reply #9 on: June 09, 2010, 03:10:53 pm »
Get rid of your for loops and put if statements in your while loop.

You're making it more complicated than it is.

See this example: http://www.sfml-dev.org/forum/viewtopic.php?t=2693