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

Author Topic: [SOLVED] sfml.Sprite inheritance nightmare  (Read 5138 times)

0 Members and 1 Guest are viewing this topic.

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
[SOLVED] sfml.Sprite inheritance nightmare
« on: January 16, 2013, 01:42:59 am »
import sfml

class BaseSprite(sfml.Sprite):
    def __init__(self, texture, arg1, arg2, arg3, rectangle=None):
        super(sfml.Sprite, self).__init__(texture, rectangle)
        self.__arg1 = arg1
        self.__arg2 = arg2
        self.__arg3 = arg3
    # ...
       
# Later, in other file...
import sfml
import media
from spritefactory import BaseSprite
from scenefactory import BaseScene

class Testsprite(BaseSprite):
    # second time inheritance
    def __init__(self, texture, arg1, arg2, arg3, rectangle=None):
        BaseSprite.__init__(texture, arg1, arg2, arg3, rectangle)
        self.setsomething(0)
       
class Scenetest(BaseScene):
    def __init__(self, scenemanager):
        BaseScene.__init__(self, scenemanager)
        self.loadmap("some/map.tmx")
        self.spritetexture = media.loadimg("some/sprite/sheet.png", False) # returns a Texture not an Image
        self.__sprite = {"mai": Test(self.spritetexture, 0, 1, 3)}
        # a bunch of code...
 

Hello! The code above is a less-detailed version of my actual source code. I'm having a nightmare trying to inheritance BaseSprite one more time. When I run the app, an awkward error shows up.

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    escena = escena_2.Maitest(director)
  File "/home/jorge/coders/desarrollo/thomas-aquinas/scenes/escena_2.py", line 22, in __init__
    "sprites/others/Mai Shiranui "
  File "graphics.pyx", line 1365, in sfml.graphics.Sprite.__cinit__ (src/sfml/graphics.cpp:23985)
TypeError: __cinit__() takes at most 2 positional arguments (4 given)
 

and if I tend to pass just one argument (i.e: the texture for the sprite) the exception change just a little:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    escena = escena_2.Maitest(director)
  File "/home/jorge/coders/desarrollo/thomas-aquinas/scenes/escena_2.py", line 21, in __init__
    self.__sprite = {"mai": Mai(self.maitext)}#, 0, self.scenemanager.window,
TypeError: __init__() takes exactly 5 arguments (2 given)

and if I don't pass any arguments at all, it changes again:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    escena = escena_2.Maitest(director)
  File "/home/jorge/coders/desarrollo/thomas-aquinas/scenes/escena_2.py", line 21, in __init__
    self.__sprite = {"mai": Mai()}#self.maitext), 0, self.scenemanager.window,
  File "graphics.pyx", line 1365, in sfml.graphics.Sprite.__cinit__ (src/sfml/graphics.cpp:23985)
TypeError: __cinit__() takes at least 1 positional argument (0 given)

For God's sake, somebody help me!! D':

cheers! :)
« Last Edit: January 19, 2013, 03:12:30 am by shackra »

GNU User
Python programmer
Blog

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
Re: sfml.Sprite inheritance nightmare
« Reply #1 on: January 16, 2013, 02:00:10 am »
I've no idea about the python binding, but in C++ one should not derive from the sprite class. It certainly is possible, but for OOP one should use the rule: composition over inheritances or derive from the classes Drawable and Transformable, but maybe Python has its own way there...

Also please, please use the code=python tag for posting! ::)

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: sfml.Sprite inheritance nightmare
« Reply #2 on: January 16, 2013, 08:35:05 pm »
I've no idea about the python binding, but in C++ one should not derive from the sprite class. It certainly is possible, but for OOP one should use the rule: composition over inheritances or derive from the classes Drawable and Transformable, but maybe Python has its own way there...

Also please, please use the code=python tag for posting! ::)

Composition over inhertance... got it. I'll try that jutsu and see how it works. Thanks!
« Last Edit: January 16, 2013, 09:00:45 pm by shackra »

GNU User
Python programmer
Blog