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

Author Topic: [SOLVED] How do I Inheritance from sfml.TransformableDrawable??  (Read 7245 times)

0 Members and 1 Guest are viewing this topic.

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
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?
« Last Edit: January 19, 2013, 03:13:15 am by shackra »

GNU User
Python programmer
Blog

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How do I Inheritance from sfml.TransformableDrawable??
« Reply #1 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.
Laurent Gomila - SFML developer

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: How do I Inheritance from sfml.TransformableDrawable??
« Reply #2 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! :)

GNU User
Python programmer
Blog

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: How do I Inheritance from sfml.TransformableDrawable??
« Reply #3 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.
Interested in using SFML with Python ? Try out its Python binding!

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: How do I Inheritance from sfml.TransformableDrawable??
« Reply #4 on: January 09, 2013, 01:27:16 am »
you miss a period at class MyDrawable(sfTransformableDrawable): :)

I'll see which solution is more elegant... thanks!

GNU User
Python programmer
Blog

Sonkun

  • Moderator
  • Full Member
  • *****
  • Posts: 241
    • View Profile
Re: How do I Inheritance from sfml.TransformableDrawable??
« Reply #5 on: January 11, 2013, 01:24:13 pm »
Thanks, I fix that!
Interested in using SFML with Python ? Try out its Python binding!

 

anything