On Tue, Jun 18, 2013 at 2:17 AM, Paul Pittlerson <[email protected]>wrote:
> 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()
>
This should be something different, is missing and old_pos term.
But, also, you need some entity / point to track.
Look at the code in test_scrolling_manager_without_tiles.py, there the keys
move a sprite, and set_focus(*the_sprite.position) would arrange the view
so the sprite is seen at screen center if restrictions allows.
If you don't want a visible actor, define a self.my_focus_position in
ScrollableLayer, update it in each step:
self.my_focus_position += 400*dt*move_dir_normalize()
and call self.parent.set_focus(self.my_focus_position) to adjust the
scrolling.
--
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.