Correct me if I am wrong, but the following code should create a red Circle at a random location. As soon as you click the window, the color should change to green.
However, it turns it black.
Why does this happen?
If I do not contain the shape inside of a class, it will work fine.
from PySFML import sf
import random
window = sf.RenderWindow(sf.VideoMode(640, 480), "Test")
class SimpleObject:
def __init__(self,color):
self.shape = sf.Shape.Circle(random.randint(0,640),random.randint(0,480),10,color)
self.shape.EnableOutline(False)
def Render(self,window):
window.Draw(self.shape)
def SetColor(self,color):
self.shape.SetColor(color)
running = True
obj = SimpleObject(sf.Color.Red)
while running:
event = sf.Event()
while window.GetEvent(event):
if event.Type == sf.Event.Closed:
running = False
if event.Type == sf.Event.MouseButtonPressed:
obj.SetColor(sf.Color.Green)
window.Clear(sf.Color(0,0,0))
obj.Render(window)
window.Display()