main.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. document.body.addEventListener('touchmove',bodyScroll,{passive: false});
  2. function bodyScroll(event){
  3. event.preventDefault();
  4. }
  5. var canvas = document.getElementById("canvas");
  6. var stage = new createjs.Stage(canvas);
  7. function init() {
  8. var comp = AdobeAn.getComposition("5529E26743974F469545223C44E61D22");
  9. var lib = comp.getLibrary();
  10. var loader = new createjs.LoadQueue(false);
  11. loader.addEventListener("fileload", function(evt) { handleFileLoad(evt, comp) });
  12. loader.addEventListener("complete", function(evt) { handleComplete(evt, comp) });
  13. loader.addEventListener("progress",loadProgressHandler);
  14. var lib = comp.getLibrary();
  15. loader.loadManifest(lib.properties.manifest);
  16. createjs.MotionGuidePlugin.install();
  17. }
  18. function handleFileLoad(evt, comp) {
  19. var loadingimages = comp.getImages();
  20. if (evt && (evt.item.type == "image")) {
  21. loadingimages[evt.item.id] = evt.result;
  22. }
  23. }
  24. function loadProgressHandler(event)
  25. {
  26. var num = Math.floor(event.progress*100);
  27. $("#loadingTxt").text(num);
  28. $("#loadingBar").css("width",num+'%');
  29. }
  30. function handleComplete(evt, comp) {
  31. //This function is always called, irrespective of the content. You can use the variable "stage" after it is created in token create_stage.
  32. var lib = comp.getLibrary();
  33. var ss = comp.getSpriteSheet();
  34. var queue = evt.target;
  35. var ssMetadata = lib.ssMetadata;
  36. for (i = 0; i < ssMetadata.length; i++) {
  37. ss[ssMetadata[i].name] = new createjs.SpriteSheet({ "images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames })
  38. }
  39. var exportRoot = new lib.assets();
  40. $(".loading").fadeOut();
  41. $(".select-dish-box .item").on("click",function(){
  42. $(this).addClass("active").siblings().removeClass("active");
  43. $(".select-dish-box .confirm").show();
  44. })
  45. $(".select-dish-box .confirm").on("click",function(){
  46. if(!$(".select-dish-box .item").hasClass("active")){
  47. alert("请选择你要做的菜")
  48. return false;
  49. }
  50. $(".select-dish-box").hide();
  51. $(".game-box").show();
  52. })
  53. function bowlAnim(callback){
  54. var anim = new TimelineMax({onComplete:callback});
  55. anim.to(exportRoot.plate,0.5,{y:"-=370", ease:Power0.easeIn})
  56. anim.to(exportRoot.bowl,0.5,{alpha:1, ease:Power0.easeIn});
  57. return anim;
  58. }
  59. function proAnim(callback){
  60. var anim = new TimelineMax({onComplete:callback});
  61. anim.to(exportRoot.pro,0.3,{rotation:"-=20", ease:Power0.easeIn})
  62. anim.to(exportRoot.pro,1,{})
  63. anim.to(exportRoot.pro,0.3,{alpha:0, ease:Power0.easeIn})
  64. anim.to(exportRoot.pro,1,{})
  65. return anim;
  66. }
  67. exportRoot.plate.addEventListener("mousedown",function(){
  68. exportRoot.plate.removeAllEventListeners();
  69. exportRoot.plate.hsr_icon1.gotoAndStop(1);
  70. exportRoot.plate.hsr_icon2.gotoAndStop(1);
  71. exportRoot.plate.hsr_icon3.gotoAndStop(1);
  72. exportRoot.plate.hsr_icon4.gotoAndStop(1);
  73. bowlAnim(function(){
  74. exportRoot.plate.hsr_icon1.addEventListener("mousedown",function(){
  75. exportRoot.plate.hsr_icon1.removeAllEventListeners();
  76. exportRoot.plate.hsr_icon1.y = 600;
  77. })
  78. exportRoot.plate.hsr_icon2.addEventListener("mousedown",function(){
  79. exportRoot.plate.hsr_icon2.removeAllEventListeners();
  80. exportRoot.plate.hsr_icon2.y = 600;
  81. })
  82. exportRoot.plate.hsr_icon3.addEventListener("mousedown",function(){
  83. exportRoot.plate.hsr_icon3.removeAllEventListeners();
  84. exportRoot.plate.hsr_icon3.y = 650;
  85. })
  86. exportRoot.plate.hsr_icon4.addEventListener("mousedown",function(){
  87. exportRoot.plate.hsr_icon4.removeAllEventListeners();
  88. exportRoot.plate.hsr_icon4.y = 600;
  89. })
  90. exportRoot.btn1.alpha = 1;
  91. exportRoot.btn1.addEventListener("mousedown",function(){
  92. exportRoot.btn1.removeAllEventListeners();
  93. exportRoot.btn1.alpha = 0;
  94. exportRoot.plate.alpha = 0;
  95. exportRoot.bowl.alpha = 0;
  96. exportRoot.pot.alpha = 1;
  97. exportRoot.pro.alpha = 1;
  98. proAnim(function(){
  99. exportRoot.pot.hsr.alpha = 1;
  100. exportRoot.btn2.alpha = 1;
  101. });
  102. })
  103. exportRoot.btn2.addEventListener("mousedown",function(){
  104. exportRoot.btn2.removeAllEventListeners();
  105. exportRoot.btn2.alpha = 0;
  106. exportRoot.blackboard.alpha = 1;
  107. exportRoot.ball1.alpha = 1;
  108. })
  109. });
  110. })
  111. //Registers the "tick" event listener.
  112. function fnStartAnimation() {
  113. stage.addChild(exportRoot);
  114. createjs.Ticker.timingMode = createjs.Ticker.RAF_SYNCHED;
  115. createjs.Ticker.addEventListener("tick", stage);
  116. }
  117. fnStartAnimation();
  118. stageBreakHandler();
  119. }
  120. // 自适应
  121. var stageWidth, stageHeight, stageScale;
  122. function stageBreakHandler(event) {
  123. if (stageWidth != $(".warp").width() || stageHeight != $(".warp").height()) {
  124. stageWidth = $(".warp").width();
  125. stageHeight = $(".warp").height();
  126. stageScale = stageWidth / 640;
  127. canvas.style.width = 640 * stageScale + 'px';
  128. canvas.style.height = 1040 * stageScale + 'px';
  129. }
  130. }