some problem
Apr 23, 2017 at 4:21pm UTC
hey guys...
I got some problem with this sfml...
I made it so that a circle is spawned at the position of a rectangle...
but the circle spawns at (0, 0)
here's the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <vector>
int main()
{
sf::Time wait;
sf::Clock Clock;
std::vector<sf::CircleShape*> Circle;
sf::RectangleShape Rect(sf::Vector2f(50, 80));
sf::RenderWindow window(sf::VideoMode(720, 480), "test" );
Rect.setPosition(sf::Vector2f(25, 40));
Rect.setOrigin(sf::Vector2f(25, 40));
Rect.setFillColor(sf::Color::Blue);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) Rect.move(0, -0.5);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) Rect.move(0, 0.5);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) Rect.move(-0.5, 0);
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) Rect.move(0.5, 0);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
{
if (wait.asMilliseconds() != 0);
else
{
Circle.push_back(new sf::CircleShape(10));
Circle.at(Circle.size() - 1)->setPosition(sf::Vector2f(Rect.getPosition().x, Rect.getPosition().y));
Circle.at(Circle.size() - 1)->setOrigin(sf::Vector2f(Rect.getPosition().x, Rect.getPosition().y));
wait = sf::milliseconds(500);
}
}
sf::Time elapsed = Clock.restart();
if (wait.asMilliseconds() != 0) wait -= elapsed;
window.clear();
window.draw(Rect);
for (unsigned int i = 0; i < Circle.size(); ++i)
{
window.draw(*Circle.at(i));
}
window.display();
}
}
P.S.
hope my long code doesnt make you guys become lazy to read the code
Last edited on Apr 23, 2017 at 4:23pm UTC
Apr 24, 2017 at 5:30am UTC
I fixed this problem now...
Topic archived. No new replies allowed.