Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Shape::SetColor issue. SFML Bug?  (Read 2874 times)

0 Members and 1 Guest are viewing this topic.

noodlesgc

  • Guest
Shape::SetColor issue. SFML Bug?
« 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()
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Shape::SetColor issue. SFML Bug?
« Reply #1 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.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Shape::SetColor issue. SFML Bug?
« Reply #2 on: July 04, 2009, 02:13:31 pm »
Shouldn't this be moved to the Python section?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Shape::SetColor issue. SFML Bug?
« Reply #3 on: July 04, 2009, 05:13:05 pm »
This is not related to Python, the problem would be the same with C++ code.
Laurent Gomila - SFML developer

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
Shape::SetColor issue. SFML Bug?
« Reply #4 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". :)

 

anything