SFML community forums

Help => Graphics => Topic started by: noodlesgc on July 04, 2009, 10:35:46 am

Title: Shape::SetColor issue. SFML Bug?
Post 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.

Code: [Select]

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()
 
Title: Shape::SetColor issue. SFML Bug?
Post by: Laurent on July 04, 2009, 10:39:35 am
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.
Title: Shape::SetColor issue. SFML Bug?
Post by: dabo on July 04, 2009, 02:13:31 pm
Shouldn't this be moved to the Python section?
Title: Shape::SetColor issue. SFML Bug?
Post by: Laurent on July 04, 2009, 05:13:05 pm
This is not related to Python, the problem would be the same with C++ code.
Title: Shape::SetColor issue. SFML Bug?
Post by: dabo on July 04, 2009, 06:59:28 pm
You are right, guess the code sample made me focus on the language used instead of the actual "problem". :)