I'm not sure what I am missing, but I'm trying to make a scrolling layer
with some of the code copied from the examples:
class world(ScrollableLayer):
is_event_handler = True
def __init__(self, handler, tileset, world_width, world_height):
super(world, self).__init__()
self.px_width = world_width
self.px_height = world_height
self.handler = handler
self.tileset = tileset
self.handler.register_event_type('on_tile_click')
self.handler.push_handlers(self)
##--------------------handle scrolling-----------
self.bindings = {
key.LEFT:'left',
key.RIGHT:'right',
key.UP:'up',
key.DOWN:'down',
}
self.buttons = {
'left':0,
'right':0,
'up':0,
'down':0,
}
self.schedule_interval(self.step, 0.1)
def step( self, dt ):
buttons = self.buttons
move_dir = eu.Vector2(buttons['right']-buttons['left'],
buttons['up']-buttons['down'])
changed = False
if move_dir:
new_pos = 400 * dt * move_dir.normalize()
changed = True
if changed:
self.refresh_tiles(new_pos)
def refresh_tiles(self, new_pos):
self.parent.set_focus(*new_pos)
def on_key_press(self, k, m ):
binds = self.bindings
if k in binds:
self.buttons[binds[k]] = 1
return True
return False
def on_key_release(self, k, m ):
binds = self.bindings
if k in binds:
self.buttons[binds[k]] = 0
return True
return False
I am sure I'm only missing something basic and obvious, but can't figure
out what it is. Help?
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.