C++ | Boundary Condition For Graphic -
my c++ knowledge pretty new i've been coding in java past 2 years. decided i'd take leap of faith , learn new language. anyway, i've been following amazing sfml tutorial online , realized little easy tastes wanted create boundary these ball objects coding can bounce around in provided window. surprise, algorithm failed me. i'm going show reduced version of guys online tutorial red circle object.
#include "stdafx.h" #include <sfml/graphics.hpp> int main() { sf::renderwindow window(sf::videomode(800, 600), "variables demo"); sf::circleshape circlered(10);//radius 10 circlered.setfillcolor(sf::color(255, 0, 0));//color red float x = true; float y = true; float xred = 100; float yred = 100; circlered.setposition(xred, yred); while (window.isopen()) { sf::event event; while (window.pollevent(event)) { if (event.type == sf::event::closed) window.close(); } window.clear(); //x , yred modified here. if (xred >= 589 || xred <= 9) x = !x; if (x = true) xred = xred + .3; else xred = xred - .3; if (yred >= 789 || yred <= 9) y = !y; if (y = true) yred = yred + .3; else yred = yred - .3; circlered.setposition(xred, yred); window.draw(circlered); window.display(); }//this end of "while" loop return 0; }
Comments
Post a Comment