def addedToWorld(self, world): """Added to the world""" super(MusicGrid, self).addedToWorld(world) # # Set up the grid to show the state self.layout = serge.blocks.utils.addActorToWorld( world, serge.blocks.layout.Grid( 'grid', 'grid', self.size, G('grid-width'), G('grid-height'), background_colour=G('grid-background-colour'), background_layer='background', ), layer_name='main', center_position=G('grid-position'), ) # # Add actors for ix in range(self.size[0]): for iy in range(self.size[1]): actor = serge.actor.Actor('cell', 'cell-%d-%d' % (ix, iy)) actor.setSpriteName('null') actor.setLayerName('main') actor.linkEvent(serge.events.E_LEFT_CLICK, self.cellClick, (ix, iy)) self.layout.addActor((ix, iy), actor) # world.addActor(self.automaton)
def addActorToWorld(world, actor, sprite_name=None, layer_name=None, center_position=None, physics=None, origin=None): """Create a new actor in the world If the center position is not specified then it is placed at the center of the screen. """ # # If not position then put at the center if origin is None and center_position is None: renderer = serge.engine.CurrentEngine().getRenderer() center_position = (renderer.width/2.0, renderer.height/2.0) # # Create the new actor if sprite_name is not None: actor.setSpriteName(sprite_name) if layer_name is not None: actor.setLayerName(layer_name) if physics: actor.setPhysical(physics) if center_position is not None: actor.moveTo(*center_position) else: actor.setOrigin(*origin) world.addActor(actor) return actor
def addSpriteActorToWorld(world, tag, name, sprite_name, layer_name, center_position=None, physics=None): """Create a new actor in the world and set the visual to be the named sprite If the center position is not specified then it is placed at the center of the screen. """ # # If not position then put at the center if center_position is None: renderer = serge.engine.CurrentEngine().getRenderer() center_position = (renderer.width / 2.0, renderer.height / 2.0) # # Create the new actor actor = serge.actor.Actor(tag, name) actor.setSpriteName(sprite_name) actor.setLayerName(layer_name) if physics: actor.setPhysical(physics) actor.moveTo(*center_position) world.addActor(actor) return actor
def updateActor(self, interval, world): """Update the actor""" # # Redraw the grid for ix in range(self.size[0]): for iy in range(self.size[1]): actor = self.layout.getActorAt((ix, iy)) state = self.automaton.getState((ix, iy)) actor.setSpriteName(self.sprites[state[0]])
def addSpriteActorToWorld(world, tag, name, sprite_name, layer_name, center_position=None, physics=None): """Create a new actor in the world and set the visual to be the named sprite If the center position is not specified then it is placed at the center of the screen. """ # # If not position then put at the center if center_position is None: renderer = serge.engine.CurrentEngine().getRenderer() center_position = (renderer.width/2.0, renderer.height/2.0) # # Create the new actor actor = serge.actor.Actor(tag, name) actor.setSpriteName(sprite_name) actor.setLayerName(layer_name) if physics: actor.setPhysical(physics) actor.moveTo(*center_position) world.addActor(actor) return actor