pkchan1987 Posted September 19, 2014 Share Posted September 19, 2014 <html><head><script type="text/javascript" src="build/phaser.min.js"></script><script>var game = new Phaser.Game(1820, 900, Phaser.AUTO, 'phaser-example', { preload: preload, create: create , update: update});var obj1;var obj2;var d=0;function preload() { game.load.image('obj1', 'cards.png' ); game.load.image('obj2', '4D.png' ); game.load.image('obj3', 'casino.png' ); game.load.image('obj4', 'chips.png' ); game.load.image('obj5', 'all.png' ); game.load.image('button', 'btn_over.png' );}function create() { obj1 = game.add.sprite(900 ,300, 'obj1'); obj3 = game.add.sprite(600 ,600, 'obj3'); obj4 = game.add.sprite(300 ,300, 'obj4'); obj5 = game.add.sprite(600 ,0, 'obj5'); button = game.add.button(600, 700, 'button', actionOnClick);}function actionOnClick () { var p = new Phaser.Point(obj1.x, obj1.y); var p2 = new Phaser.Point(600, 300); var p3 = new Phaser.Point(obj3.x, obj3.y); var p4 = new Phaser.Point(obj4.x, obj4.y); var p5 = new Phaser.Point(obj5.x, obj5.y); p.rotate(p2.x, p2.y, game.math.wrapAngle(d), true); p3.rotate(p2.x, p2.y, game.math.wrapAngle(d), true); p4.rotate(p2.x, p2.y, game.math.wrapAngle(d), true); p5.rotate(p2.x, p2.y, game.math.wrapAngle(d), true); obj1.x = p.x; obj1.y = p.y; obj3.x = p3.x; obj3.y = p3.y; obj4.x = p4.x; obj4.y = p4.y; obj5.x = p5.x; obj5.y = p5.y; d += 0.1;}function update() {}</script></head><body></body></html>Hi all, I.m going to do a lucky draw wheel spin games...but how to loop the "actionOnClick " function after click a button? how to stop the function after 5 seconds?above is my code now....does anyone can help me? Link to comment Share on other sites More sharing options...
Robske Posted September 19, 2014 Share Posted September 19, 2014 use the click to set a flag and test for that flag in the update, then do your magic in the update. after setting the flag in the click, add a setTimeOut (or something similar) and set the flag to false when it fires. Link to comment Share on other sites More sharing options...
Recommended Posts