Module cocos.actions.move_actions

Actions for moving things around based on their velocity and acceleration.

The simplest usage:

sprite = cocos.sprite.Sprite('ship.png') sprite.velocity = (100, 100) sprite.do(Move())

This will move the sprite (100, 100) pixels per second indefinitely.

Typically the sprite would be controlled by the user, so something like:

keys = <standard pyglet keyboard state handler>

class MoveShip(Move):
   def step(self, dt):
       super(MoveShip, self).step(dt)
       self.target.dr = (keys[key.RIGHT] - keys[key.LEFT]) * 360
       rotation = math.pi * self.target.rotation / 180.0
       rotation_x = math.cos(-rotation)
       rotation_y = math.sin(-rotation)
       if keys[key.UP]:
           self.target.acceleration = (200 * rotation_x, 200 * rotation_y)

ship.do(MoveShip())

Classes

  Move
Move the target based on parameters on the target.
  WrappedMove
Move the target but wrap position when it hits certain bounds.
  BoundedMove
Move the target but limit position when it hits certain bounds.
  Driver
Drive a CocosNode object around like a car in x, y according to a direction and speed.