SFML community forums

Bindings - other languages => Python => Topic started by: shackra on December 29, 2012, 12:39:02 am

Title: [SOLVED] How do I Inheritance from sfml.TransformableDrawable??
Post by: shackra on December 29, 2012, 12:39:02 am
I'm trying to write a class that Inheritance from  sfml.TransformableDrawable, however, I don't have clear at all how to use the draw method. However, I got a Segmentation Fault and an TypeError exception:

class Tile(sfml.TransformableDrawable):
    def __init__(self, image):
        sfml.TransformableDrawable.__init__(self)
        if isinstance(image, sfml.Texture):
            self.texture = image
        else:
            raise TATileImageException, ("Se esperaba un objeto del tipo "
                                         "sfml.Texture"
                                         " recibido {0}".format(type(image)))

    def draw(self, target, states):
        # states.transform = self.transform #<--- Segmentation Fault :@
        states.texture = self.texture
        target.draw(self.texture, states) #<--- TypeError: Argument 'drawable' has incorrect type (expected sfml.graphics.Drawable, got sfml.graphics.Texture)

Any help to make this class works?
Title: Re: How do I Inheritance from sfml.TransformableDrawable??
Post by: Laurent on December 29, 2012, 09:44:17 am
No idea about the segmentation fault.

For the second error, just read the doc/tutorials/whatever. You can't draw a texture, you must use a sprite.
Title: Re: How do I Inheritance from sfml.TransformableDrawable??
Post by: shackra on January 07, 2013, 05:01:47 am
No idea about the segmentation fault.

For the second error, just read the doc/tutorials/whatever. You can't draw a texture, you must use a sprite.

That was my workaround, thanks for the answer! :)
Title: Re: How do I Inheritance from sfml.TransformableDrawable??
Post by: Sonkun on January 07, 2013, 05:22:31 pm
The segmentation fault is a bug that has been fixed a while ago. Please update your bindings to the latest version (1.2). I still need to announce 1.2 release and should be done as soon as I figure out how to build sfeMovie for amd64 architecture.

About using sf.TransformableDrawable, you should prefer using sf.Drawable and use a sf.Transformable internally as mentioned in the documentation: http://python-sfml.org/1.2/tutorials.html#drawable

The reason I introduced sf.TransformableDrawable is because Python doesn't allow to subclass from two built-in classes at the same time. But using sf.Drawable is fine but requires to (re)create accessors for each sf.Transformable's accessors. For speed writing, use sf.TransformableDrawable but for elegance, use sf.Drawable and sf.Transformable.
Title: Re: How do I Inheritance from sfml.TransformableDrawable??
Post by: shackra on January 09, 2013, 01:27:16 am
you miss a period at class MyDrawable(sfTransformableDrawable): (http://python-sfml.org/1.2/tutorials.html#drawable) :)

I'll see which solution is more elegant... thanks!
Title: Re: How do I Inheritance from sfml.TransformableDrawable??
Post by: Sonkun on January 11, 2013, 01:24:13 pm
Thanks, I fix that!