Guest User

Untitled

a guest
Nov 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. ( function() {
  2.  
  3. var SpaceShooter = function() {
  4. return this;
  5. };
  6.  
  7. function init( director )
  8. {
  9. console.log( 'init' );
  10.  
  11. var scene = new CAAT.Scene().create();
  12.  
  13. var background = new CAAT.ImageActor().create();
  14. background.setImage( director.getImage( 'background' ) );
  15.  
  16. var title_image = new CAAT.ImageActor().create();
  17. title_image.setImage( director.getImage( 'title' ) );
  18. title_image.setLocation( gamecanvas.width/2 - title_image.width/2 , gamecanvas.height/2 - title_image.height );
  19.  
  20. var playbutton = new CAAT.ActorContainer().create();
  21.  
  22. var playbutton_image = new CAAT.ImageActor().create().
  23. setImage( director.getImage( 'button' ) ).
  24. enableEvents( false );
  25.  
  26. var playbutton_text = new CAAT.TextActor().create();
  27. playbutton_text.setText('Play');
  28. playbutton_text.setFont( '32px Carter One');
  29. playbutton_text.setFillStyle( '#FFFFFF' );
  30. playbutton_text.setRotation( -Math.PI*.02 );
  31. playbutton_text.calcTextSize( director );
  32. playbutton_text.setLocation(
  33. playbutton_image.width/2 - playbutton_text.textWidth/2 ,
  34. playbutton_image.height/2.5 - playbutton_text.textHeight/2
  35. );
  36. playbutton_text.enableEvents( false );
  37.  
  38. var mouseEnter = function( mouseEvent )
  39. {
  40. gamecanvas.style.cursor = 'pointer';
  41. }
  42.  
  43. var mouseExit = function( mouseExit )
  44. {
  45. gamecanvas.style.cursor = 'auto';
  46. }
  47.  
  48. playbutton.setLocation( gamecanvas.width/2 - playbutton_image.width/2 , gamecanvas.height/2 + playbutton_image.height/2 );
  49. playbutton.setSize( 217 , 77 );
  50. playbutton.mouseEnter = mouseEnter;
  51. playbutton.mouseExit = mouseExit;
  52. playbutton.mouseDown = function(){ playbutton.setScale( .95 , .95 ); }
  53. playbutton.mouseUp = function(){ playbutton.setScale( 1 , 1 ); }
  54. playbutton.addChild( playbutton_image );
  55. playbutton.addChild( playbutton_text );
  56.  
  57. console.log( 'playbutton.width: ' + playbutton.width + ', playbutton.height: ' + playbutton.height );
  58.  
  59. scene.addChild( background );
  60. scene.addChild( playbutton );
  61. scene.addChild( title_image );
  62.  
  63. return scene;
  64. }
  65.  
  66. SpaceShooter.prototype.create = function()
  67. {
  68. console.log( 'create' );
  69.  
  70. var preloader = document.getElementById( 'preloader');
  71. var gameholder = document.getElementById( 'gameholder' );
  72. gameholder.removeChild( preloader );
  73. var gamecanvas = document.getElementById( 'gamecanvas' );
  74. gamecanvas.onselectstart = function () { return false; }
  75. gamecanvas.onmousedown = function () { return false; }
  76. var director = new CAAT.Director().initialize( 550 , 400 , gamecanvas );
  77.  
  78. new CAAT.ImagePreloader().loadImages(
  79. [
  80. { id : 'background' , url : 'img/background.jpg' },
  81. { id : 'button' , url : 'img/button.png' },
  82. { id : 'title' , url : 'img/title.png' },
  83. ],
  84. function( counter , images )
  85. {
  86. if ( counter == images.length )
  87. {
  88. director.imagesCache = images;
  89. //director.setImagesCache( true );
  90. var scene01 = init( director );
  91. director.addScene( scene01 );
  92. }
  93. }
  94. );
  95.  
  96. director.loop(30);
  97. };
  98.  
  99. /**
  100. * Stats
  101. * Create stats module, and attach to top left
  102. */
  103. SpaceShooter.prototype.initStats = function() {
  104. console.log( 'initStats' );
  105. var stats = new Stats();
  106. stats.domElement.style.position = 'absolute';
  107. stats.domElement.style.left = '0px';
  108. stats.domElement.style.top = '0px';
  109.  
  110. // Update
  111. setInterval( function () {
  112. stats.update();
  113. }, 1000 / 30 );
  114.  
  115. // Add to <div>
  116. document.getElementById('gamecanvas').appendChild(stats.domElement);
  117. };
  118.  
  119. // Callback for when browser is ready
  120. var onDocumentReady = function() {
  121. // Create an instance of SpaceShooter
  122. var spaceShooterInstance = new SpaceShooter();
  123. spaceShooterInstance.create();
  124. //spaceShooterInstance.initStats();
  125. };
  126.  
  127. // Listen for ready
  128. window.addEventListener( 'load' , onDocumentReady , false );
  129. })();
Add Comment
Please, Sign In to add comment