Ejemplo n.º 1
0
    init: function () {
        Layer.superclass.init.call(this);

        var s = Director.get('sharedDirector').get('winSize');

        this.set('isRelativeAnchorPoint', false);
        this.anchorPoint = ccp(0.5, 0.5);
        this.set('contentSize', s);

        evt.addListener(this, 'ismouseenabled_changed', util.callback(this, function () {
            if (this.isRunning) {
                if (this.isMouseEnabled) {
                    EventDispatcher.get('sharedDispatcher').addMouseDelegate({delegate: this, priority: this.get('mouseDelegatePriority')});
                } else {
                    EventDispatcher.get('sharedDispatcher').removeMouseDelegate({delegate: this});
                }
            }
        }));


        evt.addListener(this, 'iskeyboardenabled_changed', util.callback(this, function () {
            if (this.isRunning) {
                if (this.isKeyboardEnabled) {
                    EventDispatcher.get('sharedDispatcher').addKeyboardDelegate({delegate: this, priority: this.get('keyboardDelegatePriority')});
                } else {
                    EventDispatcher.get('sharedDispatcher').removeKeyboardDelegate({delegate: this});
                }
            }
        }));
    },
Ejemplo n.º 2
0
    parseProblemSubset: function (subset, z, once) {
        
        var interContent = Content.buildFrom($(subset).children('TARGET')[0]);
        interContent.scale = 2;
        
        // Not the first subset
        if(!once) {
            z += RC.intermissionSpacing;
            
            // Gets the intermission value
            var inter = new Intermission(interContent, z);
            events.addListener(inter, 'changeSelector', this.startIntermission.bind(this));
            inter.idle();
			
            // Append the intermission to the list of intermissions
			this.inters.push(z);
            RS.DistanceTrigger.relPoints['checkpoint'].push(z)
			this.interList.push(inter);
			
			// Add checkpoint marker to the race track
			var opts = {
				maxScale    : 1.00,
				alignH      : 0.5,
				alignV      : 0,
				visibility  : 1,
				xCoordinate : 0,
				zCoordinate : z,
				dropoffDist : -10,
			}
			opts['content'] = new cocos.nodes.Sprite({file: '/resources/checkPoint.png',});
			opts['content'].scaleX = 1.5;
			
			var fl = new PNode(opts);
			events.addListener(fl, 'addMe', this.addMeHandler);
			fl.idle();
			fl.zOrder = -5;
        }
        else {
            this.startSelector = interContent;
        }
        
        // Interate over questions in subset
        var list = this.questionList;
        var problems = $(subset).children('QUESTION');
        for(var i=0; i<problems.length; i+=1) {
            z += RC.questionSpacing;

            // Create a question
            list[list.length] = new Question(problems[i], z);
            events.addListener(list[list.length - 1], 'questionTimeExpired', this.answerQuestion);
            events.addListener(list[list.length - 1], 'addMe', this.addMeHandler);
            list[list.length - 1].idle();
            RS.DistanceTrigger.relPoints['question'].push(z)
        }
        
        return z;
    },
Ejemplo n.º 3
0
    this.load = function () {
        // Store number of callbacks we're expecting
        this.count += this.queue.length 

        var ref, i
        for (i=0; i<this.count; i++) {
            ref = this.queue[i]

            if (!__jah__.resources[ref]) {
                console.warn("Unable to preload non-existant file: ", ref)
                didLoadResource(ref)
                continue
            }
            if (!__jah__.resources[ref].remote || __jah__.resources[ref].loaded) {
                // Already loaded
                didLoadResource(ref)
                continue
            }
            var file = resource(ref)
              , callback = (function(ref) { return function () { didLoadResource(ref) } })(ref)

            if (file instanceof remotes.RemoteResource) {
                // Notify when a resource has loaded
                listeners[ref] = events.addListener(file, 'load', callback);

                file.load()
            } else {
                setTimeout(callback, 1)
            }
        }

        this.clearQueue()
    }
    addChild: function (opts) {
        BatchNode.superclass.addChild.call(this, opts);

        var child = opts.child,
            z     = opts.z;

        if (child == this.renderTexture) {
            return;
        }

        // TODO handle texture resize

        // Watch for changes in child
        var watchEvents = ['position_before_changed',
                           'scalex_before_changed',
                           'scaley_before_changed',
                           'rotation_before_changed',
                           'anchorpoint_before_changed',
                           'opacity_before_changed',
                           'visible_before_changed'];
        evt.addListener(child, watchEvents, util.callback(this, function () {
            this.addDirtyRegion(child.get('boundingBox'));
        }));

        this.addDirtyRegion(child.get('boundingBox'));
    },
Ejemplo n.º 5
0
/**
 * Entry point for the application
 */
function main () {
    // Initialise application

    // Get director singleton
    var director = cocos.Director.sharedDirector

    // Wait for the director to finish preloading our assets
    events.addListener(director, 'ready', function (director) {
        // Create a scene and layer
        var scene = new cocos.nodes.Scene()
          , layer = new Balance(currentMap)

        layer.anchorPointInPixels.x += 200
        layer.anchorPointInPixels.y += 200


        // Add our layer to the scene
        scene.addChild(layer)

        // Run the scene
        director.replaceScene(scene)


        launchUpdates(layer)
    })

    // Preload our assets
    director.runPreloadScene()
}
Ejemplo n.º 6
0
  , run: function () {
        var test = this.getTest()

        events.addListener(test, 'next',    this.next.bind(this))
        events.addListener(test, 'back',    this.previous.bind(this))
        events.addListener(test, 'restart', this.restart.bind(this))


        var director = Director.sharedDirector
          , scene    = new Scene()

        scene.addChild(test)
        director.replaceScene(scene)

        return test
    }
 slideLabelIn: function (l, d) {
     this.addChild({child: l});
     var a = new cocos.actions.MoveTo({position: new geo.Point(15, l.position.y), duration: d});
     a.startWithTarget(l);
     l.runAction(a);
     
     events.addListener(a, 'actionComplete', this._actionComplete);
 },
 onEnter: function () {
     if (this.get('partialDraw')) {
         evt.addListener(this.get('parent'), 'istransformdirty_changed', util.callback(this, function () {
             var box = this.get('visibleRect');
             this.addDirtyRegion(box);
         }));
     }
 }
Ejemplo n.º 9
0
function launchUpdates (balance) {
    var director = cocos.Director.sharedDirector
    events.addListener(director, 'update', function () {
        for (var i=0;i<balance.children.length;i++){
            events.trigger(balance.children[i], 'update');
        }
    });
}
Ejemplo n.º 10
0
    updateCameraTracking: function (oldCamera) {
        if (this.cameraListener_) {
            events.removeListener(this.cameraListener_);
        }

        this.cameraListener_ = events.addListener(this.get('currentCamera'), 'position_changed', util.callback(this, this.updateView));
        this.updateView();
    },
Ejemplo n.º 11
0
//}}}

/**
 * @class
 * The base class all visual elements extend from
 *
 * @memberOf cocos.nodes
 */
function Node () {
    this._contentSize = new geo.Size(0, 0)
    this._anchorPoint = ccp(0.0, 0.0)
    this.anchorPointInPixels = ccp(0, 0)
    this._position = ccp(0, 0)
    this.children = []

    events.addListener(this, 'dirtytransform', this._dirtyTransform.bind(this))
}
Ejemplo n.º 12
0
/**
 * @class
 * A 2D graphic that can be animated
 *
 * @memberOf cocos.nodes
 * @extends cocos.nodes.Node
 *
 * @opt {String} file Path to image to use as sprite atlas
 * @opt {Rect} [rect] The rect in the sprite atlas image file to use as the sprite
 */
function Sprite (opts) {
    Sprite.superclass.constructor.call(this, opts)

    opts = opts || {}

    var file         = opts.file
      , textureAtlas = opts.textureAtlas
      , texture      = opts.texture
      , frame        = opts.frame
      , spritesheet  = opts.spritesheet
      , rect         = opts.rect
      , frameName    = opts.frameName

    this.offsetPosition = ccp(0, 0)
    this.unflippedOffsetPositionFromCenter = ccp(0, 0)

    if (frameName) {
        frame = SpriteFrameCache.sharedSpriteFrameCache.getSpriteFrame(frameName)
    }

    if (frame) {
        texture = frame.texture
        rect    = frame.rect
    }

    evt.addListener(this, 'dirtytransform', this._updateQuad.bind(this))
    evt.addPropertyListener(this, 'textureAtlas', 'change', this._updateTextureQuad.bind(this))

    if (file || texture) {
        textureAtlas = new TextureAtlas({file: file, texture: texture})
    } else if (spritesheet) {
        textureAtlas = spritesheet.textureAtlas
        this.useSpriteSheet = true
    } else if (!textureAtlas) {
        //throw "Sprite has no texture"
    }

    if (!rect && textureAtlas) {
        rect = {origin: ccp(0, 0), size: {width: textureAtlas.texture.size.width, height: textureAtlas.texture.size.height}}
    }

    if (rect) {
        this.rect = rect
        this.contentSize = rect.size

        this.quad = {
            drawRect: {origin: ccp(0, 0), size: rect.size},
            textureRect: rect
        }
    }

    this.textureAtlas = textureAtlas

    if (frame) {
        this.displayFrame = frame
    }
}
Ejemplo n.º 13
0
    init: function () {
        Entity.superclass.init.call(this);

        this.components = [];
        this.scheduleUpdate();

        events.addListener(this, 'position_changed', util.callback(this, function (oldVal) {
            this.set('previousPosition', oldVal);
        }));
    },
Ejemplo n.º 14
0
            init: function (opts) {
                Ground.superclass.init.call(this, opts);


                evt.addListener(this, 'point1_changed', util.callback(this, this._updatePoints));
                evt.addListener(this, 'point2_changed', util.callback(this, this._updatePoints));

                if (opts && opts.point1) {
                    this.point1 = opts.point1;
                }

                if (opts && opts.point2) {
                    this.point2 = opts.point2;
                }


                this.set('isStatic', true);
                this._updatePoints();
            },
Ejemplo n.º 15
0
    init: function (opts) {
        Sprite.superclass.init.call(this, opts);

        opts = opts || {};

        var file         = opts.file,
            textureAtlas = opts.textureAtlas,
            texture      = opts.texture,
            frame        = opts.frame,
            spritesheet  = opts.spritesheet,
            rect         = opts.rect;

        this.set('offsetPosition', ccp(0, 0));
        this.set('unflippedOffsetPositionFromCenter', ccp(0, 0));


        if (frame) {
            texture = frame.get('texture');
            rect    = frame.get('rect');
        }

        util.each(['scale', 'scaleX', 'scaleY', 'rect', 'flipX', 'flipY'], util.callback(this, function (key) {
            evt.addListener(this, key.toLowerCase() + '_changed', util.callback(this, this._updateQuad));
        }));
        evt.addListener(this, 'textureatlas_changed', util.callback(this, this._updateTextureQuad));

        if (file || texture) {
            textureAtlas = TextureAtlas.create({file: file, texture: texture});
        } else if (spritesheet) {
            textureAtlas = spritesheet.get('textureAtlas');
            this.set('useSpriteSheet', true);
        } else if (!textureAtlas) {
            //throw "Sprite has no texture";
        }

        if (!rect && textureAtlas) {
            rect = {origin: ccp(0, 0), size: {width: textureAtlas.texture.size.width, height: textureAtlas.texture.size.height}};
        }

        if (rect) {
            this.set('rect', rect);
            this.set('contentSize', rect.size);

            this.quad = {
                drawRect: {origin: ccp(0, 0), size: rect.size},
                textureRect: rect
            };
        }

        this.set('textureAtlas', textureAtlas);

        if (frame) {
            this.set('displayFrame', frame);
        }
    },
Ejemplo n.º 16
0
function PreloadScene (opts) {
    PreloadScene.superclass.constructor.call(this, opts);
    var size = Director.sharedDirector.winSize;

    if (opts.emptyImage) {
        this.emptyImage = opts.emptyImage;
    }
    if (opts.fullImage) {
        this.fullImage = opts.fullImage;
    }
    
    // Setup preloader
    var preloader = new Preloader();    // The main preloader
    preloader.addEverythingToQueue();
    this.preloader = preloader;

    // Listen for preload events
    events.addListener(preloader, 'load', function (preloader, uri) {
        var loaded = preloader.loaded;
        var count = preloader.count;
        events.trigger(this, 'load', preloader, uri);
    }.bind(this));

    events.addListener(preloader, 'complete', function (preloader) {
        events.trigger(this, 'complete', preloader);
    }.bind(this));

    // Preloader for the loading screen resources
    var loadingPreloader = new Preloader([this.emptyImage, this.fullImage]);

    // When loading screen resources have loaded then draw them
    events.addListener(loadingPreloader, 'complete', function (preloader) {
        this.createProgressBar();
        if (this.isRunning) {
            this.preloader.load();
        }

        this.isReady = true;
    }.bind(this));

    loadingPreloader.load();
}
Ejemplo n.º 17
0
    init: function () {
        World.superclass.init.call(this);

        this.set('isKeyboardEnabled', true);

        this.set('entities', BArray.create());
        this.set('keyboardObservers', BArray.create());
        this.set('cameras', BArray.create());

        events.addListener(this, 'currentcamera_changed', util.callback(this, this.updateCameraTracking));
    },
Ejemplo n.º 18
0
events.addListener = function (source, eventName, handler) {
    if (eventName instanceof Array) {
        var listeners = [];
        for (var i = 0, len = eventName.length; i < len; i++) {
            listeners.push(events.addListener(source, eventName[i], handler));
        }
        return listeners;
    } else {
        return new events.EventListener(source, eventName, handler);
    }
};
Ejemplo n.º 19
0
exports.main = function () {
    var director = cocos.Director.sharedDirector

    director.displayFPS = true

    events.addListener(director, 'ready', function (director) {
        var scene = new cocos.nodes.Scene
        scene.addChild(new PhysicsDemo)
        director.replaceScene(scene)
    })

    director.runPreloadScene()
}
Ejemplo n.º 20
0
 startTurboBoost: function() {
     if(!this.turbo && !(this.wipeoutDuration > 0) && !this.intermission && this.turboMOT == null) {
         this.turbo = true;
         this.preTurbo = this.zVelocity;
         
         var tm = this.speedChange(this.turboSpeed - this.zVelocity, 0.1);
         this.turboMOT = tm;
         events.addListener(tm, 'Completed', this.turboCompleted);
         
         return true;
     }
     
     return false;
 },
Ejemplo n.º 21
0
 endTurboBoost: function() {
     if(this.turbo) {
         var tm = this.turboMOT;
         if(tm != null) {
             tm.kill();
             this.turboMOT = null;
         }
         
         this.turbo = false;
         var tm = this.speedChange(this.preTurbo - this.zVelocity, 0.1);
         this.turboMOT = tm;
         events.addListener(tm, 'Completed', this.turboCompleted);
     }
 },
Ejemplo n.º 22
0
    bindTo: function (key, target, targetKey, noNotify) {
        targetKey = targetKey || key;
        var self = this;
        this.unbind(key);

        var oldVal = this.get(key);

        // When bound property changes, trigger a 'changed' event on this one too
        getBindings(this)[key] = events.addListener(target, targetKey.toLowerCase() + '_changed', function (oldVal) {
            self.triggerChanged(key, oldVal);
        });

        addAccessor(this, key, target, targetKey, noNotify);
    },
    init: function (opts) {
        BatchNode.superclass.init.call(this, opts);

        var size = opts.size || geo.sizeMake(1, 1);
        this.set('partialDraw', opts.partialDraw);

        evt.addListener(this, 'contentsize_changed', util.callback(this, this._resizeCanvas));
        
        this._dirtyRects = [];
        this.set('contentRect', geo.rectMake(0, 0, size.width, size.height));
        this.renderTexture = RenderTexture.create(size);
        this.renderTexture.sprite.set('isRelativeAnchorPoint', false);
        this.addChild({child: this.renderTexture});
    },
Ejemplo n.º 24
0
    init: function (opts) {
        ProgressBar.superclass.init.call(this, opts);
        var size = new geo.Size(272, 32);
        this.set('contentSize', size);

        var s;
        if (opts.emptyImage) {
            s = Sprite.create({file: opts.emptyImage, rect: new geo.Rect(0, 0, size.width, size.height)});
            s.set('anchorPoint', new geo.Point(0, 0));
            this.set('emptySprite', s);
            this.addChild({child: s});
        }
        if (opts.fullImage) {
            s = Sprite.create({file: opts.fullImage, rect: new geo.Rect(0, 0, 0, size.height)});
            s.set('anchorPoint', new geo.Point(0, 0));
            this.set('fullSprite', s);
            this.addChild({child: s});
        }

        events.addListener(this, 'maxvalue_changed', util.callback(this, 'updateImages'));
        events.addListener(this, 'value_changed', util.callback(this, 'updateImages'));

        this.updateImages();
    },
exports.main = function () {
    // Initialise test
    var director = cocos.Director.get('sharedDirector');

    director.attachInView(document.getElementById('cocos2d-tests'));
    director.set('displayFPS', true);

    events.addListener(director, 'ready', function (director) {
        var scene = nodes.Scene.create();
        scene.addChild({child: nextAction().create()});
        director.replaceScene(scene);
    });

    director.runPreloadScene();
};
Ejemplo n.º 26
0
    createProgressBar: function () {
        var preloader = this.preloader;
        var size = Director.sharedDirector.winSize;

        var progressBar = new ProgressBar({emptyImage: this.emptyImage, fullImage: this.fullImage});

        progressBar.position = new geo.Point(size.width / 2, size.height / 2);

        this.progressBar = progressBar;
        this.addChild({child: progressBar});

        events.addListener(preloader, 'load', function (preloader, uri) {
            progressBar.maxval = preloader.count;
            progressBar.val = preloader.loaded;
        });
    },
/**
 * Entry point for the application
 */
function main () {
    // Initialise application

    // Get director singleton
    var director = Director.sharedDirector

    // Wait for the director to finish preloading our assets
    events.addListener(director, 'ready', function (director) {
        // Create a scene and layer
        var scene = new SceneRecurso()
       // Run the scene
        director.replaceScene(scene)
    })

    // Preload our assets
    director.runPreloadScene()
}
Ejemplo n.º 28
0
/**
 * Entry point for the application
 */
function main () {
    // Initialise application

    // Get director singleton
    var director = Director.sharedDirector

    // Wait for the director to finish preloading our assets
    events.addListener(director, 'ready', function (director) {
        // Create a scene and layer
        var title_scene = new Scene(), t_layer = new ReadyForGame()
        title_scene.addChild(t_layer)

        // Run the scene
        director.replaceScene(title_scene)
    })

    // Preload our assets
    director.runPreloadScene()
}
Ejemplo n.º 29
0
exports.main = function () {
    var director = Director.sharedDirector
    director.displayFPS = true

    // Start the first test when everything has loaded
    events.addListener(director, 'ready', function () {
        var testSuite = new TestSuite()

        // Import all the tests
        testList.forEach(function (testName) {
            testSuite.tests.push(require('./' + testName))
        })

        testSuite.run()
    })

    // Load everything
    director.runPreloadScene()
}
Ejemplo n.º 30
0
// Main ////////////////////////////////////////////////////////////////////////////////////////////

// Initialise application
function main() {
    // From: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
    // This defines function.bind for web browsers that have not implemented it:
    // Firefox < 4 ; Chrome < 7 ; IE < 9 ; Safari (all) ; Opera (all)
    if (!Function.prototype.bind) {  
        Function.prototype.bind = function (oThis) {  
        
            if (typeof this !== "function") { // closest thing possible to the ECMAScript 5 internal IsCallable function  
                throw new TypeError("Function.prototype.bind - what is trying to be fBound is not callable");  
            }

            var aArgs = Array.prototype.slice.call(arguments, 1),
                fToBind = this,
                fNOP = function () {},
                fBound = function () {
                    return fToBind.apply(this instanceof fNOP ? this : oThis || window, aArgs.concat(Array.prototype.slice.call(arguments)));
                };

            fNOP.prototype = this.prototype;
            fBound.prototype = new fNOP();

            return fBound;
        };
    }
    
    // Setup the director
    var director = cocos.Director.sharedDirector;
    
    events.addListener(director, 'ready', function(director) {
        var scene = new cocos.nodes.Scene();     // Create a scene
        var app = new FluencyApp();              // Create the layers

        // Add our layers to the scene
        scene.addChild(app);

        // Run the scene
        director.replaceScene(scene);
    });
    
    director.attachInView();
    director.preloadScene = new PreloadScene({emptyImage: '/resources/Loader/LoadingScreen00.png', fullImage: '/resources/Loader/LoadingScreen16.png'});
    director.runPreloadScene();
}