YannThorimbert / Thorpy

A GUI library for Pygame
http://www.thorpy.org
Other
31 stars 5 forks source link

Issue with Shadows #5

Closed CVersi closed 4 years ago

CVersi commented 4 years ago

Following along with the examples, I ran into issues in both the Shadows example and the Special Effects example. Here is where the error is in the Special Effects Example, line 49:

if thorpy.constants.CAN_SHADOWS: #set shadow
       thorpy.makeup.add_static_shadow(e_ship, {"target_altitude":5,
                                            "shadow_radius":3,
                                            "sun_angle":40,
                                            "alpha_factor":0.6})

The error I was getting in both examples:

Traceback (most recent call last):
  File "C:\Users\Owner\Desktop\ThorpyExamples\0010_Smoke_Fire_debris.py", line 50, in <module>
    thorpy.makeup.add_static_shadow(e_ship, {"target_altitude":5,
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\thorpy\painting\makeup.py", line 12, in add_static_shadow
    shadowel = StaticShadow(element)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\thorpy\elements\_makeuputils\_shadow.py", line 33, in __init__
    Element.__init__(self, "", elements, normal_params)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\thorpy\elements\element.py", line 39, in __init__
    self.finish()
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\thorpy\elements\_makeuputils\_shadow.py", line 125, in finish
    painter = self._get_shadow_painter()
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\thorpy\elements\_makeuputils\_shadow.py", line 95, in _get_shadow_painter
    shadow = self._get_raw_shadow()
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\site-packages\thorpy\elements\_makeuputils\_shadow.py", line 65, in _get_raw_shadow
    target_img = self.target.get_image(self.capture_state)
AttributeError: 'StaticShadow' object has no attribute 'target'

So I went to the StaticShadow file and found that it does indeed have a target attribute:

class StaticShadow(Element):

    def __init__(self, target, elements=None, normal_params=None):
        Element.__init__(self, "", elements, normal_params)
        self.link(target)
        self.sun_angle = SUN_ANGLE
        ...

self.target is created in the link method, which is called on the second line of the initialization method above:

def link(self, target):
        self.target = target
        self.target.add_elements([self])
        self.target.set_blit_before(self)
        self.target._shadow = self
        self.target._overframe = True
        if self.target._jail:
            self.set_jailed(self.target._jail)

This is my first time posting something like this on github, so bear with me if I didn't do something correct. I wanted to ensure you were aware of the issue and tried to be as thorough as possible. Thorpy version is 1.6.3, Python version is 3.8.2, Pygame is 1.9.6. Operating systems tried on are Windows 10 and Ubuntu 18.04 LTS.

YannThorimbert commented 4 years ago

Hi, thank you for your remark. I just commited a new version which fixes the bug. Let me know if it does not solve your problem.