Advertisement
Guest User

Promise with Tween of Cocos Creator

a guest
Apr 4th, 2020
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. onLoad()
  2. {
  3. this.moveTo(this.cursor, 1, cursorToStopBtn)
  4.             .then(() => this.bouncing(this.stopButton, 1.1, 4) )
  5.             .then(() => this.moveTo(this.cursor, 1, cursorToInfoBtn))
  6.             .then(() => this.bouncing(this.infoButton, 1.1, 4));
  7. }
  8.  
  9. private moveTo(anyNode: cc.Node, duration: number, toPosition: cc.Vec2): Promise<unknown>
  10.     {
  11.         return new Promise((resolve, reject) =>
  12.         {
  13.             cc.tween(anyNode)
  14.                 .to(duration, { position: toPosition })
  15.                 .call(resolve)
  16.                 .start();
  17.         });
  18.     }
  19.  
  20. private bouncing(node: cc.Node, scaleRate: number, repeat: number)
  21.     {
  22.         return new Promise((resolve, reject) =>
  23.         {
  24.             repeat = Math.max(1, repeat);
  25.             cc.tween(node)
  26.                 .repeat(repeat, cc.tween()
  27.                     .to(0.5, { scale: scaleRate })
  28.                     .to(0.5, { scale: 1 })
  29.                 )
  30.                 .call(resolve)
  31.                 .start();
  32.         });
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement