SFML community forums
Help => Graphics => Topic started by: noodlesgc on July 04, 2009, 10:35:46 am
-
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()
-
There are two colors:
- the color which is assigned to all the points of the shape during creation
- the global color, inherited from sf::Drawable
The two colors are separate, you can change any of it independantly. They are then modulated at render time to give the final color of the shape. That's why you get black : red * green = black.
-
Shouldn't this be moved to the Python section?
-
This is not related to Python, the problem would be the same with C++ code.
-
You are right, guess the code sample made me focus on the language used instead of the actual "problem". :)