Permalink
Browse files

Upgrades: content value added to PerspectiveNode eliminates need for …

…PerspectiveSprite. LabelBG inherits from Node, as delimiter representations can be passed to PerspectiveNode. Question and PerspectiveNode now align delimiters correctly. main no longer spawns trees in the upper left corner of the screen.
  • Loading branch information...
1 parent a63c3f7 commit 9ba46890be519d9653591d161dee20f200359398 John Conomikes committed Sep 13, 2011
View
@@ -17,9 +17,7 @@ Copyright 2011, Carnegie Learning
// Import the cocos2d module
var cocos = require('cocos2d');
-var PNode = require('PerspectiveNode').PerspectiveNode;
-
-var LabelBG = PNode.extend({
+var LabelBG = cocos.nodes.Node.extend({
label : null, //The label that the class wraps
bgColor: '#FFFFFF', //The color of the background that will be behind the label
init: function(opts) {
@@ -30,22 +30,30 @@ var PerspectiveNode = cocos.nodes.Node.extend({
added : false, // True once added to the scene
lockX : false, // Set to true to lock X value
lockY : false, // Set to true to lock Y value
- alignV : 0, // Vertical alignment of the node (0 left - 0.5 center - 1 right)
- alignH : 0, // Horizontal alignment of the node (0 top - 0.5 center - 1 bottom)
+ alignV : 0, // Vertical alignment of the node (0 top - 0.5 center - 1 bottom)
+ alignH : 0, // Horizontal alignment of the node (0 right - 0.5 center - 1 left)
dropoffDist : -10, // Distance behind the camera that node requests removal from scene
zVelocity : 0, // Meters per second speed along the Z axis
xVelocity : 0, // Meters per second speed along the X axis
+ content : null, // Content to be displayed in the node
init: function(opts) {
- PerspectiveNode.superclass.init.call(this);
+ PerspectiveNode.superclass.init.call(this, opts);
this.set('position', new geom.Point(0, 0));
+ this.set('anchorPoint', new geom.Point(0, 0));
//Set properties from the option object
- util.each('visibility minScale maxScale xCoordinate zCoordinate silent lockX lockY alignV alignH dropoffDist zVelocity xVelocity'.w(), util.callback(this, function (name) {
+ util.each('visibility minScale maxScale xCoordinate zCoordinate silent lockX lockY alignV alignH dropoffDist zVelocity xVelocity content'.w(), util.callback(this, function (name) {
if (opts[name]) {
this.set(name, opts[name]);
}
}));
+
+ if(this.get('content') != null) {
+ this.get('content').set('anchorPoint', new geom.Point(0, 0));
+ this.addChild({child: this.get('content')});
+ this.set('contentSize', this.get('content').get('contentSize'));
+ }
},
// Explicitly start update, even if not in scene
@@ -113,7 +121,7 @@ var PerspectiveNode = cocos.nodes.Node.extend({
// Check to see if X axis is locked
if(!lockX) {
screenX = PerspectiveNode.roadOffset + PerspectiveNode.roadWidthPix / 2 * (1 + scale * 2.0 * (this.get('xCoordinate') / PerspectiveNode.roadWidth));
- screenX += this.get('alignH') * this.get('contentSize').width * displayScale;
+ screenX -= this.get('alignH') * this.get('contentSize').width * displayScale;
}
else {
screenX = this.get('alignH') * this.get('contentSize').width * displayScale;
@@ -1,36 +0,0 @@
-/*
-Copyright 2011, Carnegie Learning
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-var cocos = require('cocos2d');
-
-var PerspectiveNode = require('PerspectiveNode').PerspectiveNode;
-
-var PerspectiveSprite = PerspectiveNode.extend({
- sprite: null,
- init: function(opts) {
- PerspectiveSprite.superclass.init.call(this, opts);
-
- if(opts.hasOwnProperty('sprite')) {
- var sprite = cocos.nodes.Sprite.create({file: opts['sprite'],});
- this.addChild({child: sprite});
- this.set('sprite', sprite);
-
- this.scheduleUpdate();
- }
- }
-});
-
-exports.PerspectiveSprite = PerspectiveSprite
View
@@ -43,28 +43,38 @@ var Question = PNode.extend({
this.set('correctAnswer', ans);
// Create and display the question content
- var opts = {
+ // TODO: Clean up this mess
+ // TODO: Get this working with arbitrary content for delimeters (just pass in PNodes?)
+ var lOpt = {
string : d1,
fontColor : '#000000',
bgColor : '#FFFFFF',
zOrder : 100,
+ }
+
+ var opts = {
lockY : true,
silent : true,
minScale : 0.75,
- alignH : 0.5,
+ alignH : 1,
alignV : 1,
visibility : 3,
xCoordinate : -1.5,
- zCoordinate : z
+ zCoordinate : z,
}
- var delim = LabelBG.create(opts);
+ opts['content'] = LabelBG.create(lOpt);
+ opts['content'].set('position', new geom.Point(opts['content'].get('contentSize').width / 2, 0))
+ var delim = PNode.create(opts);
delim.scheduleUpdate();
this.addChild({child: delim});
this.set('coneL', delim);
- opts['string'] = d2;
+ lOpt['string'] = d2;
opts['xCoordinate'] = 1.5;
- delim = LabelBG.create(opts);
+ opts['alignH'] = 0;
+ opts['content'] = LabelBG.create(lOpt);
+ opts['content'].set('position', new geom.Point(opts['content'].get('contentSize').width / 2, 0))
+ delim = PNode.create(opts);
delim.scheduleUpdate();
this.addChild({child: delim});
this.set('coneR', delim);
@@ -88,14 +98,22 @@ var Question = PNode.extend({
update: function(dt) {
Question.superclass.update.call(this, dt);
- if(this.get('added') && this.get('answeredCorrectly') == null) {
- var te = this.get('timeElapsed') + dt;
- this.set('timeElapsed', te);
-
- // TODO: Get the chaseDist from the player, otherwise answers will be up to a meter late
- if(PNode.cameraZ + 6 >= this.get('zCoordinate')) {
- events.trigger(this, "questionTimeExpired", this);
+ if(this.get('added')) {
+ if(this.get('answeredCorrectly') == null) {
+ var te = this.get('timeElapsed') + dt;
+ this.set('timeElapsed', te);
+
+ // TODO: Get the chaseDist from the player, otherwise answers will be up to a meter late
+ if(PNode.cameraZ + 6 >= this.get('zCoordinate')) {
+ events.trigger(this, "questionTimeExpired", this);
+ }
}
+
+ // Pulls the delimiters more onto the lane lines as they progress down the screen
+ var shift = (this.get('position').y - PNode.horizonStart) / PNode.horizonHeight / 1.5;
+
+ this.get('coneL').set('alignH', 1 - shift);
+ this.get('coneR').set('alignH', 0 + shift);
}
},
});
View
@@ -70,11 +70,11 @@ var FluencyApp = KeyboardLayer.extend({
var list = [];
for(var i=0; i<6; i+=1) {
- var inter = Intermission.create(20+i, i*500+10);
+ var inter = Intermission.create(20000+i, i*500+10);
events.addListener(inter, 'changeSelector', this.intermissionHandler.bind(this));
inter.kickstart();
for(var j=1; j<4; j+=1) {
- list[list.length] = Question.create(1, 10+i, 30+i, i*500 + j*150 + 10);
+ list[list.length] = Question.create(1, 10000+i, 30000+i, i*500 + j*150 + 10);
events.addListener(list[list.length - 1], 'questionTimeExpired', this.answerQuestion.bind(this));
events.addListener(list[list.length - 1], 'addMe', this.addMeHandler.bind(this));
list[list.length - 1].kickstart();
@@ -87,14 +87,18 @@ var FluencyApp = KeyboardLayer.extend({
player.set('position', new geo.Point(400, 450));
this.set('player', player);
- for(var t=0; t<3300; t += Math.ceil(Math.random()*6+4)) {
+ var sprite = cocos.nodes.Sprite.create({file: '/resources/tree_1.png',});
+
+ for(var t=10; t<3300; t += Math.ceil(Math.random()*6+4)) {
if(Math.random() < 0.25) {
- var p = PSprite.create({xCoordinate: 4 * Math.random() + 5.5, zCoordinate: t, sprite: '/resources/tree_1.png', silent: true})
- this.addChild({child: p})
+ var p = PNode.create({xCoordinate: 4 * Math.random() + 5.5, zCoordinate: t, content: sprite, alignH: 0.5, alignV: 0.5})
+ events.addListener(p, 'addMe', this.addMeHandler.bind(this));
+ p.kickstart();
}
if(Math.random() < 0.25) {
- var p = PSprite.create({xCoordinate: -4 * Math.random() - 5.5, zCoordinate: t, sprite: '/resources/tree_1.png', silent: true})
- this.addChild({child: p})
+ var p = PNode.create({xCoordinate: -4 * Math.random() - 5.5, zCoordinate: t, content: sprite, alignH: 0.5, alignV: 0.5})
+ events.addListener(p, 'addMe', this.addMeHandler.bind(this));
+ p.kickstart();
}
}

0 comments on commit 9ba4689

Please sign in to comment.