def load_from_filename(self, imgname, center_location=(0,0)): gfx = Config.get_graphic_engine() self._img_proxy = gfx.load_image(imgname) width, height = self._img_proxy.get_size() if width > self._size[0]: self._size[0] = width if height > self._size[1]: self._size[1] = height if isinstance(center_location, str): if center_location == 'centered': self._bb_center = self._size / 2. elif center_location == 'centered_bottom': self._bb_center = self._size.copy() self._bb_center[0] /= 2. else: self._bb_center = np.asarray(center_location)
def load_frames_from_filenames(self, state, frames_fnames=[], center_location=(0,0), fps=30): ''' Load frames from images (one image per file) for a given state state: A valid state of the Sprite State Machine. If state equals __default__, these frames are used for each state without any frames. If frames_fnames is [] then no sprite is displayed for the given state. frames_fnames: liste of filenames. center_location: - tuple of coordinates in pixel from the bottom left corner of the images (the same shift for all images). - list of coordinates in pixel from the bottom left corner of the images (one shift per image). or - 'centered': the center is centered on the images. or - 'centered_bottom': the center is centered on the bottom of the images. fps: number of frames per seconds. ''' self._frames[state] = [ \ Config.get_graphic_engine().load_image(fname) \ for fname in frames_fnames] self._refresh_delay[state] = int(1000 / fps) loc = [] for img in self._frames[state]: width, height = img.get_size() if width > self._size[0]: self._size[0] = width if height > self._size[1]: self._size[1] = height if isinstance(center_location, str): for img in self._frames[state]: width, height = img.get_size() if center_location == 'centered': loc.append(np.array([width, height])/2.) elif center_location == 'centered_bottom': loc.append(np.array([width/2., height])) elif isinstance(center_location, list): loc = center_location else: loc = [center_location] * len(self._frames[state]) if center_location == 'centered': self._bb_center = self._size / 2. elif center_location == 'centered_bottom': self._bb_center = self._size self._bb_center[0] /= 2. self._frames_center_location[state] = loc
def __init__(self, name, context, layer=2, size=None, shift=(0, 0), center_location=(0,0), color=(0, 0, 0), alpha=128): Sprite.__init__(self, name, context, layer) gfx = Config.get_graphic_engine() self._img_proxy= gfx.get_uniform_surface(shift, size, color, alpha) if isinstance(center_location, str): width, height = np.array(self._img_proxy.get_size()) if center_location == 'centered': self._bb_center = np.array([width, height]) / 2. elif center_location == 'centered_bottom': self._bb_center = np.array([width / 2., height]) elif center_location == 'top_left': self._bb_center = np.array([0., 0.]) else: self._bb_center = np.asarray(center_location) self._size = size self.set_location(shift)
def display_context(self, context): Config.get_graphic_engine().display_context(self, context)
def update(self, dt): #FIXME : on devrait pas avoir a updater le dialog? Sprite.update(self, dt) # for motions self.backend_repr = Config.get_graphic_engine().load_text(\ self.text, self.font, self.font_size, self._location[0], self._location[1])
def display(self): Config.get_graphic_engine().clean() for context in self._possible_states.values(): if context.is_visible: context.display() Config.get_graphic_engine().flip()