Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ( function() {
- var SpaceShooter = function() {
- return this;
- };
- function init( director )
- {
- console.log( 'init' );
- var scene = new CAAT.Scene().create();
- var background = new CAAT.ImageActor().create();
- background.setImage( director.getImage( 'background' ) );
- var title_image = new CAAT.ImageActor().create();
- title_image.setImage( director.getImage( 'title' ) );
- title_image.setLocation( gamecanvas.width/2 - title_image.width/2 , gamecanvas.height/2 - title_image.height );
- var playbutton = new CAAT.ActorContainer().create();
- var playbutton_image = new CAAT.ImageActor().create().
- setImage( director.getImage( 'button' ) ).
- enableEvents( false );
- var playbutton_text = new CAAT.TextActor().create();
- playbutton_text.setText('Play');
- playbutton_text.setFont( '32px Carter One');
- playbutton_text.setFillStyle( '#FFFFFF' );
- playbutton_text.setRotation( -Math.PI*.02 );
- playbutton_text.calcTextSize( director );
- playbutton_text.setLocation(
- playbutton_image.width/2 - playbutton_text.textWidth/2 ,
- playbutton_image.height/2.5 - playbutton_text.textHeight/2
- );
- playbutton_text.enableEvents( false );
- var mouseEnter = function( mouseEvent )
- {
- gamecanvas.style.cursor = 'pointer';
- }
- var mouseExit = function( mouseExit )
- {
- gamecanvas.style.cursor = 'auto';
- }
- playbutton.setLocation( gamecanvas.width/2 - playbutton_image.width/2 , gamecanvas.height/2 + playbutton_image.height/2 );
- playbutton.setSize( 217 , 77 );
- playbutton.mouseEnter = mouseEnter;
- playbutton.mouseExit = mouseExit;
- playbutton.mouseDown = function(){ playbutton.setScale( .95 , .95 ); }
- playbutton.mouseUp = function(){ playbutton.setScale( 1 , 1 ); }
- playbutton.addChild( playbutton_image );
- playbutton.addChild( playbutton_text );
- console.log( 'playbutton.width: ' + playbutton.width + ', playbutton.height: ' + playbutton.height );
- scene.addChild( background );
- scene.addChild( playbutton );
- scene.addChild( title_image );
- return scene;
- }
- SpaceShooter.prototype.create = function()
- {
- console.log( 'create' );
- var preloader = document.getElementById( 'preloader');
- var gameholder = document.getElementById( 'gameholder' );
- gameholder.removeChild( preloader );
- var gamecanvas = document.getElementById( 'gamecanvas' );
- gamecanvas.onselectstart = function () { return false; }
- gamecanvas.onmousedown = function () { return false; }
- var director = new CAAT.Director().initialize( 550 , 400 , gamecanvas );
- new CAAT.ImagePreloader().loadImages(
- [
- { id : 'background' , url : 'img/background.jpg' },
- { id : 'button' , url : 'img/button.png' },
- { id : 'title' , url : 'img/title.png' },
- ],
- function( counter , images )
- {
- if ( counter == images.length )
- {
- director.imagesCache = images;
- //director.setImagesCache( true );
- var scene01 = init( director );
- director.addScene( scene01 );
- }
- }
- );
- director.loop(30);
- };
- /**
- * Stats
- * Create stats module, and attach to top left
- */
- SpaceShooter.prototype.initStats = function() {
- console.log( 'initStats' );
- var stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.left = '0px';
- stats.domElement.style.top = '0px';
- // Update
- setInterval( function () {
- stats.update();
- }, 1000 / 30 );
- // Add to <div>
- document.getElementById('gamecanvas').appendChild(stats.domElement);
- };
- // Callback for when browser is ready
- var onDocumentReady = function() {
- // Create an instance of SpaceShooter
- var spaceShooterInstance = new SpaceShooter();
- spaceShooterInstance.create();
- //spaceShooterInstance.initStats();
- };
- // Listen for ready
- window.addEventListener( 'load' , onDocumentReady , false );
- })();
Add Comment
Please, Sign In to add comment