1
Graphics / Draw shape function
« on: April 01, 2020, 11:03:25 pm »
I have this chunk of code that draws a square:
I want to have some kind of function/class that does this. The problem I'm having is that when I put this into a function, it doesn't work anymore, because the "window" object is declared inside of main{}. Is there a way I can pass in the renderwindow from main{} to a function?
full code:
p.s. i'm very new to cpp development, i might be asking the wrong question
RectangleShape rect (Vector2f(100.f, 100.f));
rect.setFillColor(Color(100, 50, 200));
rect.setPosition(50.f, 50.f);
window.draw(rect);
rect.setFillColor(Color(100, 50, 200));
rect.setPosition(50.f, 50.f);
window.draw(rect);
I want to have some kind of function/class that does this. The problem I'm having is that when I put this into a function, it doesn't work anymore, because the "window" object is declared inside of main{}. Is there a way I can pass in the renderwindow from main{} to a function?
full code:
(click to show/hide)
p.s. i'm very new to cpp development, i might be asking the wrong question