def show_message(self, msg, callback=None): w, h = director.get_window_size() self.msg = cocos.text.Label(msg, font_size=52, font_name=consts['view']['font_name'], anchor_y='center', anchor_x='center', width=w, multiline=True, align="center") self.msg.position = (w / 2.0, h) self.add(self.msg) actions = ( ac.Show() + ac.Accelerate(ac.MoveBy((0, -h / 2.0), duration=0.1)) + ac.Delay(1) + ac.Accelerate(ac.MoveBy((0, -h / 2.0), duration=0.1)) + ac.Hide() ) if callback: actions += ac.CallFunc(callback) self.msg.do(actions)
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)