Преглед изворни кода

Lots of bugs in NodeSprite that needed fixing :)

master
Bryan Miller пре 6 година
родитељ
комит
eb042b28d7
1 измењених фајлова са 20 додато и 11 уклоњено
  1. +20
    -11
      game/gbe/nodes.py

+ 20
- 11
game/gbe/nodes.py Прегледај датотеку

"rect":[0,0,0,0], "rect":[0,0,0,0],
"image":"", "image":"",
"scale":[1.0, 1.0], "scale":[1.0, 1.0],
"scale_dirty":True,
"surface":None "surface":None
} }


if surf is not None: if surf is not None:
# Do some prescaling work, if needed. # Do some prescaling work, if needed.
if self._NODESPRITE_DATA["scale_dirty"]: if self._NODESPRITE_DATA["scale_dirty"]:
self._NODESPRITE_DATA["scale_dirty"] = False
self._NODESPRITE_UpdateFrameSurface(surf)
self._NODESPRITE_UpdateScaleSurface(scale, surf) self._NODESPRITE_UpdateScaleSurface(scale, surf)
fsurf = surf # Initial assumption that the surface is also the "frame" fsurf = surf # Initial assumption that the surface is also the "frame"
# If we have a "frame" surface, however, let's get it and blit the rect into the frame surface. # If we have a "frame" surface, however, let's get it and blit the rect into the frame surface.
# Call on all children # Call on all children
Node._render(self, surface) Node._render(self, surface)


def _NODESPRITE_UpdateFrameSurface(self, surf):
rect = self.rect
ssize = surf.get_size()
if rect[2] == ssize[0] and rect[3] == ssize[1]:
if "frame_surf" in self._NODESPRITE_DATA:
del self._NODESPRITE_DATA
return

if "frame_surf" not in self._NODESPRITE_DATA:
self._NODESPRITE_DATA["frame_surf"] = pygame.Surface((rect[2], rect[3]), pygame.SRCALPHA, surf)
else:
fsurf = self._NODESPRITE_DATA["frame_surf"]
fsize = fsurf.get_size()
if fsize[0] != rect[2] or fsize[1] != rect[3]:
self._NODESPRITE_DATA["frame_surf"] = pygame.Surface((rect[2], rect[3]), pygame.SRCALPHA, surf)



def _NODESPRITE_UpdateScaleSurface(self, scale, surf): def _NODESPRITE_UpdateScaleSurface(self, scale, surf):
self._NODESPRITE_DATA["scale_dirty"] = False
ssurf = None ssurf = None
if "scale_surf" in self._NODESPRITE_DATA: if "scale_surf" in self._NODESPRITE_DATA:
ssurf = self._NODESPRITE_DATA["scale_surf"] ssurf = self._NODESPRITE_DATA["scale_surf"]
elif rect[1] + rect[3] > isize[1]: elif rect[1] + rect[3] > isize[1]:
rect[3] = isize[1] - rect[1] rect[3] = isize[1] - rect[1]


fssize = [0,0]
if rect[2] > 0 and rect[3] > 0:
if rect[2] < isize[0] or rect[1] < isize[1]:
surf = self._NODESPRITE_DATA["surface"]()
self._NODESPRITE_DATA["frame_surf"] = pygame.Surface((rect[2], rect[3]), pygame.SRCALPHA, surf)
if fssize[0] > 0 and fssize[1] > 0:
pass
elif "frame_surf" in self._NODESPRITE_DATA:
del self._NODESPRITE_DATA["frame_surf"]
self._NODESPRITE_DATA["scale_dirty"] = True







Loading…
Откажи
Сачувај