Пример #1
0
def shake():
    """Predefined action that performs a slight rotation and then goes back to the original rotation
    position.
    """
    angle = 5
    duration = 0.05

    rot = ac.Accelerate(ac.RotateBy(angle, duration), 2)
    rot2 = ac.Accelerate(ac.RotateBy(-angle * 2, duration), 2)
    return rot + (rot2 + ac.Reverse(rot2)) * 2 + ac.Reverse(rot)
Пример #2
0
    def mouse_move_off(self):
        """The card is unselected (move mouse from it)."""

        # Restore my z-order.
        _new_z_order, _ = self._find_myself()
        del self.parent.children[_new_z_order[0]]
        self.parent.children.insert(self._orig_z_order[0],
                                    (self._orig_z_order[1], self))

        self.do(actions.Reverse(self._move_actions))
Пример #3
0
def main():
    director.init( resizable=True, fullscreen=False )
    main_scene = cocos.scene.Scene()

    main_scene.add( BackgroundLayer(), z=0 )

    action1 = ac.ShuffleTiles( grid=(16,8), seed=2, duration=3 )
    action1 = ac.Reverse(action1)
    
    # In real code after a sequence of grid actions the StopGrid() action
    # should be called. Omited here to stay in the last grid action render
    main_scene.do( action1 )
    director.run (main_scene)
Пример #4
0
    def __init__(self):
        # Blueish color
        super(HelloActions, self).__init__(
            r=64,
            g=64,
            b=224,
            a=255,
        )

        label = text.Label(
            'Hello World',
            font_name='Microsoft YaHei UI',
            font_size=32,
            anchor_x='center',
            anchor_y='center',
        )
        label.position = 320, 240

        self.add(label)

        # Add a cocos Sprite.
        sprite_ = sprite.Sprite('HSCard.png')
        sprite_.position = 320, 240

        # [NOTE] The sprite will 3 times bigger.
        sprite_.scale = 0.58

        # [NOTE] z is the precedence of the sprite. This sprite will on the top of the label.
        self.add(sprite_, z=1)

        # [LEARN] We create a ScaleBy action. It will scale 3 times the object in 2 seconds:
        scale = actions.ScaleBy(3, duration=2)

        # [LEARN] '+' is sequence action here.
        # 'Reverse' reverse the action.
        label.do(actions.Repeat(scale + actions.Reverse(scale)))

        sprite_.do(actions.Repeat(actions.Reverse(scale) + scale))
Пример #5
0
def main():
    director.init(resizable=True)
    director.set_depth_test()

    main_scene = cocos.scene.Scene()
    main_scene.add(BackgroundLayer(), z=0)

    action1 = ac.WavesTiles3D(waves=2, amplitude=70, grid=(16, 16), duration=3)
    action1 = ac.Reverse(action1)

    # In real code after a sequence of grid actions the StopGrid() action
    # should be called. Omited here to stay in the last grid action render
    main_scene.do(action1)
    director.run(main_scene)
Пример #6
0
def main():
  global keyboard # Declare this as global so it can be accessed within class methods.
  # Initialize the window
  director.init(width=size[0], height=size[1], autoscale=True, resizable=True)

  # Create a layer and add a sprite to it.
  player_layer = layer.Layer()
  molecule = sprite.Sprite('sprites/molecule.png')
  molecule.scale = 2
  player_layer.add(molecule, z=1)
  scale = actions.ScaleBy(3, duration=2)

  # Add a Label, because we can.
  label = cocos.text.Label('Hello, world@' + str(deltaTime), font_name='Times New Roman', font_size=32, anchor_x='left', anchor_y='center')
  label.position = 0, size[1]/2
  label.velocity = 0, 0
  player_layer.add(label)

  # Set initial position and velocity.
  molecule.position = (size[0]/2, size[1]/2)
  molecule.velocity = (0, 0)

  # Set the sprite's movement class and run some actions.
  molecule.do(actions.Repeat(scale + actions.Reverse(scale)))

  label.do(Me())

  # Rotate the entire player_layer (includes ALL nodes, will rotate ONCE)
  player_layer.do(actions.RotateBy(360, duration=10))

  # Create a scene and set its initial layer.
  main_scene = scene.Scene(player_layer)

  # Set the sprite's movement class.
  keyboard = key.KeyStateHandler()
  director.window.push_handlers(keyboard)

  # Play the scene in the window.
  director.run(main_scene)