PageRenderTime 617ms CodeModel.GetById 503ms app.highlight 5ms RepoModel.GetById 105ms app.codeStats 0ms

/js/DemoCircles/DemoView.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 96 lines | 45 code | 12 blank | 39 comment | 0 complexity | 617f37112ae6131c241e9f4051d7f120 MD5 | raw file
 1/**
 2 File:
 3 AbstractServerGame.js
 4 Created By:
 5 Mario Gonzalez
 6 Project:
 7 RealtimeMultiplayerNodeJS
 8 Abstract:
 9 This class is the base Game controller in RealtimeMultiplayerGame on the server side.
10 It provides things such as dropping players, and contains a ServerNetChannel
11 Basic Usage:
12 [This class is not instantiated! - below is an example of using this class by extending it]
13
14 (function(){
15		MyGameClass = function() {
16			return this;
17 		}
18
19		RealtimeMultiplayerGame.extend(MyGameClass, RealtimeMultiplayerGame.AbstractServerGame, null);
20	};
21 Version:
22 1.0
23 */
24(function () {
25    DemoApp.DemoView = function () {
26        this.setupCAAT();
27        this.setupStats();
28    };
29
30    DemoApp.DemoView.prototype = {
31        // Properties
32        caatDirector: null,				// CAAT Director instance
33        caatScene: null,				// CAAT Scene instance
34        stats: null,				// Stats.js instance
35
36        // Methods
37        setupCAAT: function () {
38            this.caatScene = new CAAT.Scene(); // Create a scene, all directors must have at least one scene - this is where all your stuff goes
39            this.caatScene.create();	// Notice we call create when creating this, and ShapeActor below. Both are Actors
40            this.caatScene.setFillStyle('#000000');
41
42            this.caatDirector = new CAAT.Director().initialize(DemoApp.Constants.GAME_WIDTH, DemoApp.Constants.GAME_HEIGHT); // Create the director instance
43            this.caatDirector.addScene(this.caatScene); // Immediately add the scene once it's created
44
45            // Start the render loop, with at 60FPS
46//			this.caatDirector.loop(60);
47        },
48
49        /**
50         * Updates our current view, passing along the current actual time (via Date().getTime());
51         * @param {Number} gameClockReal The current actual time, according to the game
52         */
53        update: function (gameClockReal) {
54            var delta = gameClockReal - this.caatDirector.timeline;
55            this.caatDirector.render(delta);
56            this.caatDirector.timeline = gameClockReal;
57        },
58
59        /**
60         * Creates a Stats.js instance and adds it to the page
61         */
62        setupStats: function () {
63            var container = document.createElement('div');
64            this.stats = new Stats();
65            this.stats.domElement.style.position = 'absolute';
66            this.stats.domElement.style.top = '0px';
67            container.appendChild(this.stats.domElement);
68            document.body.appendChild(container);
69        },
70
71        addEntity: function (anEntityView) {
72            console.log("Adding Entity To CAAT", anEntityView);
73            this.caatScene.addChild(anEntityView);
74        },
75
76        removeEntity: function (anEntityView) {
77            console.log("Removing Entity From CAAT", anEntityView);
78            this.caatScene.removeChild(anEntityView);
79        },
80
81        /**
82         * Insert the CAATDirector canvas into an HTMLElement
83         * @param {String} id An HTMLElement id
84         */
85        insertIntoHTMLElementWithId: function (id) {
86            document.getElementById(id).appendChild(this.caatDirector.canvas);
87        },
88
89        // Memory
90        dealloc: function () {
91            this.director.destroy();
92        }
93    };
94})();
95
96