def process(self, window, dt): for layer in self.entityset: for e in self.entityset[layer]: e.update(dt) for entity in self.layer_change_list: change = self.layer_change_list[entity] from_layer = change[0] to_layer = change[1] try: self.entityset[from_layer].remove(entity) except: pass if not to_layer in self.entityset: self.entityset[to_layer] = set() self.entityset = OrderedDict( sorted(self.entityset.items(), key=lambda t: t[0])) self.entityset[to_layer].add(entity) self.layer_change_list = dict() for e in self.children: e.build_global_transform(sf.Transform()) scale = window.height / (16.0 + self.camera.zoom) transform = sf.Transform().translate(window.size / 2.0) transform = transform.scale(sf.Vector2( scale, scale)) * self.camera.global_transform.inverse for layer in self.entityset: for e in self.entityset[layer]: e.ondraw(window, transform)
def draw(self, window, transform): scale = sf.Vector2(window.width / 768.0, window.height / 768.0) t = sf.Transform().scale(sf.Vector2(1, 1) * scale.y) scaled_bounds = sf.Vector2(self.text.local_bounds.size.x * scale.y, self.text.local_bounds.size.y * scale.y) t.translate((window.size - scaled_bounds) / 2.0) self.__renderstate.transform = t * self.global_transform window.draw(self.text, self.__renderstate)
def draw(self, window, transform): position = self.position fullscreen_offset = ((window.height * 2.0) - 1) self.global_transform.translate( sf.Vector2(position.x * fullscreen_offset, position.y * fullscreen_offset)) self.sprite.ratio = self.windowed_ratio(window) t = sf.Transform().translate(window.size / 2.0) self.__renderstate.transform = transform = t * self.global_transform window.draw(self.sprite, self.__renderstate) self.position = position
def __init__(self, layer=0): super(Entity, self).__init__(layer) self.enabled = True self.global_transform = sf.Transform() self.collider = None
def test_init(self): self.assertEqual(sf.Transform().matrix, sf.Transform.IDENTITY.matrix) self.assertRaises(TypeError, sf.Transform, *range(10))
def random_transform(self): return sf.Transform(*[random.triangular(0.0, 5.0) for i in range(9)])