Quellcode durchsuchen

NodeSurface can now use a clear color. By default, it will not clear it's surface at the start of a render.

master
Bryan Miller vor 6 Jahren
Ursprung
Commit
c9a36a8044
1 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. +24
    -0
      game/gbe/nodes.py

+ 24
- 0
game/gbe/nodes.py Datei anzeigen

@@ -326,6 +326,9 @@ class NodeSurface(Node2D):
except NodeError as e:
raise e
# TODO: Update this class to use the _NODE*_DATA={} structure.
self._NODESURFACE_DATA={
"clear_color":None
}
self._scale = (1.0, 1.0)
self._scaleToDisplay = False
self._scaleDirty = False
@@ -458,12 +461,33 @@ class NodeSurface(Node2D):
self._surface.fill(pygame.Color(0,0,0,0))
self._updateTransformSurface()

def set_clear_color(self, color):
if color is None:
self._NODESURFACE_DATA["clear_color"] = None
elif isinstance(color, (list, tuple)):
clen = len(color)
if clen == 3 or clen == 4:
iscolor = lambda v: isinstance(v, int) and v >= 0 and v < 256

if iscolor(color[0]) and iscolor(color[1]) and iscolor(color[2]):
if clen == 3 or (clen == 4 and iscolor(color[3])):
self._NODESURFACE_DATA["clear_color"] = pygame.Color(*color)

def get_clear_color(self):
cc = self._NODESURFACE_DATA["clear_color"]
if cc == None:
return None
return (cc.r, cc.g, cc.b, cc.a)

def _render(self, surface):
if self._surface is None:
self.set_surface()
if self._surface is not None:
if self._scaleDirty:
self._updateTransformSurface()
cc = self._NODESURFACE_DATA["clear_color"]
if cc is not None:
self._surface.fill(cc)
Node2D._render(self, self._surface)
else:
Node2D._render(self, surface)

Laden…
Abbrechen
Speichern