#y no circle appearing

27 messages · Page 1 of 1 (latest)

analog mango
#
#include <iostream>
#include <SFML/Graphics.hpp>
#include <ctime>
#include <cstdlib>
#include <random>

const int WIDTH = 800;
const int HEIGHT = 600;

struct Ball
{

    sf::CircleShape circle;

    Ball(int width, int height)
    {
        float x = width / 2.f;
        float y = height / 2.f;

        float radius = 50.f;
        circle.setRadius(radius);
        sf::Color color = sf::Color::White;
        circle.setFillColor(color);
        circle.setPosition(sf::Vector2f(x, y));
    };
};

int main()
{
    sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Pong");
    Ball pingPong = Ball(WIDTH, WIDTH);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color::Black);
        window.draw(pingPong.circle);
        window.display();
    }

    return 0;
}
clang++ Pong.cpp -std=c++11 -o PongExecutable -I/opt/homebrew/Cellar/sfml/2.6.1/include -L/opt/homebrew/Cellar/sfml/2.6.1/lib -lsfml-graphics -lsfml-window -lsfml-system
open kilnBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

tardy shoal
#

is it compiling? what do you actually see?

analog mango
tardy shoal
#

welp, looks like it should work

analog mango
#

oh

#

is it the colour

tardy shoal
#

why?

#

youre setting the colour of the circle to white

#

and the background to black

#

should work

analog mango
#

i have tho

#

imma put some prints in

tardy shoal
#

not sure how thats going to help but okay

#

you should consider just debugging

#

if youre going to print

analog mango
#

yh that is for my debugging im probably a bit dumb to say this but i have never used the debugger

#

found something

Pong.cpp:32:35: error: no member named 'x' in 'Ball'
    std::cout << "x:" << pingPong.x << "\n"
                         ~~~~~~~~ ^
Pong.cpp:33:35: error: no member named 'y' in 'Ball'
              << "y:" << pingPong.y << "\n"
                         ~~~~~~~~ ^
Pong.cpp:34:40: error: no member named 'radius' in 'Ball'
              << "radius:" << pingPong.radius << "\n"
                              ~~~~~~~~ ^
Pong.cpp:35:40: error: no member named 'color' in 'Ball'
              << "colour:" << pingPong.color << "\n";
                              ~~~~~~~~ ^
4 errors generated.
int main()
{
    sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "Pong");
    Ball pingPong = Ball(WIDTH, WIDTH);
    std::cout << "x:" << pingPong.x << "\n"
              << "y:" << pingPong.y << "\n"
              << "radius:" << pingPong.radius << "\n"
              << "colour:" << pingPong.color << "\n";

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
#

i have an idea

magic mica
analog mango
#
//i like put these things here not in the constructor

struct Ball
{

    sf::CircleShape circle;
    float x, y, radius;
    sf::Color color;

    Ball(int width, int height)
    {
        x = width / 2.f;
        y = height / 2.f;

        radius = 50.f;
        circle.setRadius(radius);
        color = sf::Color::White;
        circle.setFillColor(color);
        circle.setPosition(sf::Vector2f(x, y));
    };
};
magic mica
#

circle.getPosition() and i dont know about the rest, one thing you can do is to move them out of constructor body and make them members.

analog mango
#

did i like make them members here

magic mica
analog mango
#

still doesnt work