Ok Guys no Problem I appreciate the help here is the code for my tutorial level and then tranisition into the endscreen level it seems to happen though with the ending of all my levels the huge slowdown but it only happens once then after it has happend the game runs perfectly
BaseLevel.js
init:function(level)
{
this.stopMusic();
this.screenSize = cc.director.getWinSize();
GameCons.touchRestart = false;
GameCons.currLevel = level;
GameCons.levelTime = 0;
},
// init space of chipmunk
initPhysics:function()
{
//1. new space object
this.space = new cp.Space();
//2. setup the Gravity
this.space.gravity = cp.v(0, -(1150 * GameCons.scaleFactor));
this.space.addCollisionHandler(SpriteTag.player, SpriteTag.floor, this.collisionFloorBegin.bind(this),null, null, this.collisionFloorEnd.bind(this));
this.space.addCollisionHandler(SpriteTag.player, SpriteTag.goal, this.collisionGoal.bind(this),null, null, null);
this.space.addCollisionHandler(SpriteTag.player, SpriteTag.saw, this.collisionSaw.bind(this),null, null, null);
this.space.addCollisionHandler(SpriteTag.player, SpriteTag.boost, this.collisionBoost.bind(this),null,null,null);
},
createPauseMenu:function()
{
this.pauseMenu = new PauseMenu();
this.addChild(this.pauseMenu);
this.pauseMenu.visible = false;
this.pauseBtn = new ccui.Button("PauseBtn.png","PauseBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
this.pauseBtn.x = this.screenSize.width * 0.05;
this.pauseBtn.y = this.screenSize.height * 0.92;
this.pauseBtn.setScale(GameCons.scaleFactor);
this.pauseBtn.addTouchEventListener(this.pauseGame, this);
this.addChild(this.pauseBtn);
},
createParticleSys:function(posX,posY)
{
//create particle system
this.particle = cc.ParticleSystem.create(res.starsParticles_plist);
this.particle.setPosition(posX * GameCons.scaleFactor, posY * GameCons.scaleFactor);
this.particle.stopSystem();
this.particle.setScale(GameCons.scaleFactor);
this.addChild(this.particle);
},
collisionBoost:function()
{
},
stopMusic:function()
{
cc.audioEngine.stopMusic();
},
startMusic:function()
{
//cc.audioEngine.playMusic(res.levelSnd_wav,true);
},
getMapWidth:function()
{
return this.map00.getContentSize().width;
},
startGameSeq:function(scale,xPos,yPos)
{
//Set position for entry effect
this.setScale(scale, scale);
this.setPosition(-(xPos * GameCons.scaleFactor), -yPos);
},
startGameSeqOdd:function(scaleX,scaleY,xPos,yPos)
{
//Set position for entry effect
this.setScale(scaleX, scaleY);
this.setPosition((xPos * GameCons.scaleFactor), yPos);
},
createNumbers:function()
{
//Create the numbers for start sequence
this.one = new cc.Sprite("#one.png");
this.one.setPosition(this.screenSize.width / 2,this.screenSize.height / 2);
this.two = new cc.Sprite("#two.png");
this.two.setPosition(this.one.getPositionX(),this.one.getPositionY());
this.three = new cc.Sprite("#three.png");
this.three.setPosition(this.one.getPositionX(), this.one.getPositionY());
this.go = new cc.Sprite("#go.png");
this.go.setPosition(this.one.getPositionX(), this.one.getPositionY());
this.addChild(this.one);
this.addChild(this.two);
this.addChild(this.three);
this.addChild(this.go);
this.one.setVisible(false);
this.two.setVisible(false);
this.three.setVisible(false);
this.go.setVisible(false);
if(GameCons.isAccelLvl == true)
{
this.tiltLbl = new cc.LabelBMFont("Tilt", res.menuFont_ttf);
this.tiltLbl.setScale(1 * GameCons.scaleFactor,1 * GameCons.scaleFactor)
this.tiltLbl.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.8));
this.tiltLbl.color = cc.color.RED;
this.addChild(this.tiltLbl);
this.outline = new cc.Sprite("#iPad.png");
this.outline.setPosition(cc.winSize.width * 0.5, cc.winSize.height * 0.5);
this.outline.setVisible(true);
this.outline.setScale(2);
this.outline.setRotation(90);
this.addChild(this.outline);
}
},
startSequnce:function(xPos,yPos)
{
//Start sequence actions
var scaleAction = cc.scaleTo(3, 1, 1);
var moveAction = cc.moveBy(3, xPos * GameCons.scaleFactor, yPos);
var setHud = cc.callFunc(this.setHudStart,this);
var setThree = cc.callFunc(this.setNum,this);
var setTwo = cc.CallFunc(this.setNum2,this);
var setOne = cc.CallFunc(this.setNum3,this);
var setGo = cc.CallFunc(this.setGo,this);
var startLevel = cc.CallFunc(this.startLevel,this);
var rotateFunc = cc.callFunc(this.rotateFunc, this);
//Run the actions for the start sequence
this.runAction(cc.sequence(cc.delayTime(3),scaleAction));
if(GameCons.isAccelLvl == true)
{
this.runAction(cc.sequence(cc.delayTime(3),moveAction,rotateFunc,cc.delayTime(2.5),setThree,cc.DelayTime(1),setTwo,cc.delayTime(1),setOne,
cc.delayTime(1),setGo,cc.delayTime(0.5),startLevel));
}
else
{
this.runAction(cc.sequence(cc.delayTime(3),moveAction,setThree,cc.DelayTime(1),setTwo,cc.delayTime(1),setOne,
cc.delayTime(1),setGo,cc.delayTime(0.5),startLevel));
}
},
rotateFunc:function()
{
var rotate = cc.rotateBy(1, 30, 30);
var rotateBack = cc.rotateBy(1,-60,-60);
var fade = cc.callFunc(this.deleteTilt,this);
this.outline.runAction(cc.sequence(rotate,rotateBack,fade));
},
deleteTilt:function()
{
this.outline.runAction(cc.fadeTo(1, 0));
this.tiltLbl.runAction(cc.fadeTo(1, 0));
},
collisionSaw:function (arbiter, space)
{
//Set collision to true for particle
this.coll = true;
},
startLevel:function()
{
//Set go vis and show the hud
//this.go.setVisible(false);
this.setHudStart();
},
setGo:function()
{
//set visible
this.one.setVisible(false);
this.go.setVisible(true);
},
setNum:function()
{
//set visible
this.three.setVisible(true);
},
setNum2:function()
{
//set visible
this.three.setVisible(false);
this.two.setVisible(true);
},
setNum3:function()
{
//set visible
this.two.setVisible(false);
this.one.setVisible(true);
},
setHudStart:function()
{
//remove start numbers and set hud visible
this.deletNumberTextures();
this.HudLayer.setVisible(true);
if(!GameCons.isMulti)
this.pauseBtn.visible = true;
this.stopHud = false;
GameCons.canMove = true;
},
deletNumberTextures:function()
{
//deletion of the textures
this.removeChild(this.one);
this.removeChild(this.two);
this.removeChild(this.three);
this.removeChild(this.go);
},
pauseGame:function(sender,type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
cc.audioEngine.playEffect(res.buttonClick_mp3);
this.pausedPressed();
break;
break;
}
},
pausedPressed:function()
{
this.pauseMenu.visible = true;
cc.director.pause();
},
endLevel:function()
{
cc.director.runScene(new cc.TransitionFade(1.5, new EndScene()));
},
collisionFloorBegin:function (arbiter, space)
{
GameCons.canJump = true;
},
collisionFloorEnd:function(arbiter,space)
{
GameCons.canJump = false;
},
});
Turoial Level.js
//For Creating Scenes
var INIT_TUT = false;
var tutLayer = baseLayer.extend
({
goal:null,
label:null,
highlight:null,
highlightBtn:null,
ctor:function ()
{
this._super();
this.init(0);
//Set up Physics
this.initPhysics();
this.player = new Player(200,500,this.space);
this.HudLayer = new HudLayer();
//Create Map
this.map00 = new cc.TMXTiledMap(res.tutMap2);
//Set backGround
this.bg = new cc.Sprite(res.sky_png);
var content = this.bg.getContentSize();
this.bg.x = content.width / 2;
this.bg.y = content.height / 2;
this.bg.setScale(GameCons.scaleFactor * 2.4,GameCons.scaleFactor * 2);
//Get Size Vars
this.mapWidth = this.getMapWidth();
this.loadObjects(this.map00, 0);
//Create a Game Layer
this.gLayer = new cc.Layer();
this.gLayer.addChild(this.bg,0);
this.gLayer.addChild(this.player);
this.gLayer.addChild(this.map00,0);
this.addChild(this.gLayer);
this.addChild(this.HudLayer);
var goals = this.map00.getObjectGroup("Goal");
var goalArray = goals.getObjects();
this.goal = new Goal(this.space,cc.p(goalArray[0]["x"] + goalArray[0]["width"] / 2 - 10,goalArray[0]["y"] + goalArray[0]["height"] / 2));
this.gLayer.addChild(this.goal);
this.goal.setScale(GameCons.scaleFactor,GameCons.scaleFactor)
//Highlight boxes added
this.highlight = cc.Sprite("#highlight.png");
this.highlight.x = this.screenSize.width * 0.9;
this.highlight.y = this.screenSize.height * 0.94;
this.highlight.setVisible(false);
this.addChild(this.highlight);
this.highlightBtn = cc.Sprite("#highlightBtn.png");
if(!GameCons.switchedControls)
this.highlightBtn.x = this.screenSize.width * 0.1;
else
this.highlightBtn.x = this.screenSize.width * 0.7;
this.highlightBtn.y = this.screenSize.height * 0.07;
this.highlightBtn.setScale(0.5, 0.5);
this.addChild(this.highlightBtn);
//This check for display which tutorial information to show
var s = "";
if (!cc.sys.capabilities.hasOwnProperty('touches'))
{
this.highlightBtn.setVisible(false);
s = "A";
}
var string = "Press" + " " + s + " " + "to Move Left";
//Set Text for tutorial
this.label = new cc.LabelTTF(string);
this.label.setFontSize(80 * GameCons.scaleFactor);
this.label.setPosition(cc.p(this.screenSize.width / 2,this.screenSize.height / 2));
this.label.setColor(cc.color(255, 0, 0));
this.addChild(this.label);
//Actions for tutorial level
var sprite_action2 = cc.FadeTo.create(2.0, 0);
var sprite_action = cc.FadeIn.create(1.0);
var highlightLeft = cc.callFunc(this.setHighlightLeft,this);
var highLightRight = cc.callFunc(this.moveHighlightBtn,this);
var highLightJump = cc.callFunc(this.moveHighlightJump,this);
var highlight = cc.callFunc(this.setHighlight,this);
var finish = cc.CallFunc.create(this.loadRightMove, this);
var changeText = cc.CallFunc.create(this.loadJumpText, this);
var timerText = cc.CallFunc.create(this.loadTimerText, this);
var endSequence = cc.CallFunc.create(this.endSeq, this);
var delayTime = 0.5;
//Run the sequence of actions on the label
this.label.runAction(cc.Sequence(cc.delayTime(delayTime), sprite_action2,highlightLeft,cc.delayTime(delayTime),finish,highLightRight,sprite_action,sprite_action2,
highlightLeft,cc.delayTime(delayTime),changeText,highLightJump,sprite_action,sprite_action2,highlightLeft,cc.delayTime(delayTime),timerText,
sprite_action,highlight,sprite_action2,
endSequence));
//Set a "Camera" Effect to follow the player
var followAction = cc.Follow.create(this.player.sprite2,cc.rect(0,0, this.mapWidth, this.map00.getContentSize().height));
this.gLayer.runAction(followAction);
GameCons.canMove = true;
this.createPauseMenu();
this.createParticleSys(500, 400);
this.scheduleUpdate();
this.startMusic();
},
endSeq:function()
{
//Create goal to let player move on to next level
this.highlight.setVisible(false);
},
setHighlight:function()
{
this.highlight.setVisible(true);
},
setHighlightLeft:function()
{
if (cc.sys.capabilities.hasOwnProperty('touches'))
this.highlightBtn.setVisible(false);
},
moveHighlightBtn:function()
{
if (cc.sys.capabilities.hasOwnProperty('touches'))
{
if(!GameCons.switchedControls)
this.highlightBtn.x = cc.director.getWinSize().width * 0.3;
else
this.highlightBtn.x = cc.director.getWinSize().width * 0.9;
this.highlightBtn.setVisible(true);
}
},
moveHighlightJump:function()
{
if (cc.sys.capabilities.hasOwnProperty('touches'))
{
if(!GameCons.switchedControls)
this.highlightBtn.x = cc.director.getWinSize().width * 0.8;
else
this.highlightBtn.x = cc.director.getWinSize().width * 0.2;
this.highlightBtn.y = cc.director.getWinSize().height * 0.4;
this.highlightBtn.setScale(2, 2);
this.highlightBtn.setVisible(true);
}
},
loadObjects:function(map,mapIndex)
{
//Load all objects in the arrays
var platforms = map.getObjectGroup("Floor");
var platArray = platforms.getObjects();
for (var i = 0; i < platArray.length; i++)
{
var platform = new Platform(null,this.space,
cc.p(platArray[i]["x"] + platArray[i]["width"] / 2,platArray[i]["y"] + platArray[i]["height"] / 2),platArray[i]["width"],platArray[i]["height"]);
}
var walls = map.getObjectGroup("wall");
var wallArray = walls.getObjects();
for (var i = 0; i < wallArray.length; i++)
{
var wall = new Wall(this.space,
cc.p(wallArray[i]["x"] + wallArray[i]["width"] / 2,wallArray[i]["y"] + wallArray[i]["height"] / 2),wallArray[i]["width"],wallArray[i]["height"]);
}
},
loadRightMove:function()
{
var s = "";
if (!cc.sys.capabilities.hasOwnProperty('touches'))
s = "D";
this.label.setString("Press" + " " + s + " " + "to Move Right");
},
loadJumpText:function()
{
var s = "";
if (!cc.sys.capabilities.hasOwnProperty('touches'))
s = "W";
this.label.setString("Press" + " " + s + " " + "to Jump");
},
loadTimerText:function()
{
this.label.setString("This Is Your Current Time");
},
collisionGoal:function (arbiter,space)
{
this.player.stopMoving();
INIT_TUT = false;
cc.audioEngine.playEffect(res.sparkleSound_mp3);
this.particle.resetSystem();
GameCons.canMove = false;
var sprite_action = cc.moveBy(1, 100, 0);
var endLev = cc.callFunc(this.endLevel,this);
this.player.runAction(cc.sequence(cc.delayTime(1),endLev));
},
draw:function(ctx)
{
this._super();
},
update:function(dt)
{
if(GameCons.touchRestart == true)
{
this.player.moveForCollision();
GameCons.touchRestart = false;
}
this.space.step(dt);
}
});
var tutScene = cc.Scene.extend({
onEnter:function ()
{
this._super();
if (INIT_TUT == false)
{
INIT_TUT = true;
var layer = new tutLayer();
this.addChild(layer);
}
}
And EndScreen.js
ctor:function ()
{
this._super();
if(GameCons.isAccelLvl) GameCons.isAccelLvl = false;
var bg = new cc.Sprite(res.mainBg_png);
bg.setAnchorPoint(0, 0);
this.addChild(bg);
var windowBg = new cc.Sprite("#LevelCompBg.png");
windowBg.x = cc.director.getWinSize().width * 0.5;
windowBg.y = cc.director.getWinSize().height * 0.5;
windowBg.setScale(GameCons.scaleFactor);
this.addChild(windowBg);
this.getNumOfStars();
var label = new cc.LabelBMFont("Level Complete", res.menuFont_ttf);
label.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor);
if(GameCons.scaleFactor == 1)
label.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.9));
else if(GameCons.scaleFactor == 2)
label.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.84));
label.color = cc.color.RED;
this.addChild(label);
var time = new cc.Sprite("#Time.png");
if(GameCons.scaleFactor == 1)
{
time.x = cc.winSize.width * 0.46;
time.y = cc.winSize.height * 0.43;
}
else if(GameCons.scaleFactor == 2)
{
time.x = cc.winSize.width * 0.46;
time.y = cc.winSize.height * 0.44;
}
this.addChild(time);
var timeLabel = new cc.LabelBMFont("Time ", res.menuFont_ttf);
timeLabel.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor);
if(GameCons.scaleFactor == 1)
timeLabel.setPosition(cc.p(cc.winSize.width * 0.36, cc.winSize.height * 0.43));
else if(GameCons.scaleFactor == 2)
timeLabel.setPosition(cc.p(cc.winSize.width * 0.36, cc.winSize.height * 0.44));
timeLabel.color = cc.color.RED;
this.addChild(timeLabel);
var gameTime = new cc.LabelBMFont(GameCons.levelTime, res.menuFont_ttf);
gameTime.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor)
if(GameCons.scaleFactor == 1)
gameTime.setPosition(cc.p(cc.winSize.width * 0.58, cc.winSize.height * 0.43));
else if(GameCons.scaleFactor == 2)
gameTime.setPosition(cc.p(cc.winSize.width * 0.58, cc.winSize.height * 0.44));
gameTime.color = cc.color.RED;
this.addChild(gameTime);
var level = new cc.LabelBMFont("Level", res.menuFont_ttf);
level.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor);
if(GameCons.scaleFactor == 1)
level.setPosition(cc.p(cc.winSize.width * 0.36, cc.winSize.height * 0.24));
else if(GameCons.scaleFactor)
level.setPosition(cc.p(cc.winSize.width * 0.36, cc.winSize.height * 0.29));
level.color = cc.color.RED;
this.addChild(level);
var currLevel = new cc.LabelBMFont(GameCons.currLevel + 1, res.menuFont_ttf);
currLevel.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor);
if(GameCons.scaleFactor == 1)
currLevel.setPosition(cc.p(cc.winSize.width * 0.58, cc.winSize.height * 0.24));
else if(GameCons.scaleFactor == 2)
currLevel.setPosition(cc.p(cc.winSize.width * 0.58, cc.winSize.height * 0.29));
currLevel.color = cc.color.RED;
this.addChild(currLevel);
if(GameCons.scaleFactor == 1)
{
var btnHeight = cc.winSize.height * 0.08;
var confirmHeight = cc.winSize.height * 0.35;
}
else if(GameCons.scaleFactor == 2)
{
var btnHeight = cc.winSize.height * 0.12;
var confirmHeight = cc.winSize.height * 0.37;
}
this.fbBtn = new ccui.Button("fbBtn.png","fbBtnDown.png","",ccui.Widget.PLIST_TEXTURE);
this.fbBtn.setScale(0.64 * GameCons.scaleFactor,0.64 * GameCons.scaleFactor);
this.fbBtn.x = cc.winSize.width * 0.55;
this.fbBtn.y = btnHeight;
this.fbBtn.addTouchEventListener(this.fbShare, this);
this.addChild(this.fbBtn);
this.restartBtn = new ccui.Button("RetryBtn.png","RetryBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
this.restartBtn.setScale(0.72 * GameCons.scaleFactor,0.72 * GameCons.scaleFactor);
this.restartBtn.x = cc.winSize.width * 0.45;
this.restartBtn.y = btnHeight;
this.restartBtn.addTouchEventListener(this.touchResume, this);
this.addChild(this.restartBtn);
this.nextBtn = new ccui.Button("PlayBtn.png","PlayBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
this.nextBtn.setScale(0.7 * GameCons.scaleFactor,0.7 * GameCons.scaleFactor);
this.nextBtn.x = cc.winSize.width * 0.35;
this.nextBtn.y = btnHeight;
this.nextBtn.addTouchEventListener(this.nextLevel, this);
this.addChild(this.nextBtn);
this.quitBtn = new ccui.Button("HomeBtn.png","HomeBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
this.quitBtn.setScale(0.7 * GameCons.scaleFactor,0.7 * GameCons.scaleFactor);
this.quitBtn.x = cc.winSize.width * 0.65;
this.quitBtn.y = btnHeight;
this.quitBtn.addTouchEventListener(this.touchQuit, this);
this.addChild(this.quitBtn);
this.setStars();
this.checkStars();
this.whiteBg = cc.LayerColor.create(new cc.Color(128,128,128,160));
this.addChild(this.whiteBg);
this.whiteBg.visible = false;
this.confirmBg = new cc.Sprite("#ConfirmBg.png");
this.confirmBg.x = cc.winSize.width * 0.5;
this.confirmBg.y = cc.winSize.height * 0.6;
this.confirmBg.setScale(GameCons.scaleFactor);
this.addChild(this.confirmBg);
this.confirmBg.visible = false;
this.exitStr = new cc.LabelBMFont(" Are you Sure \n You want to Exit?", res.menuFont_ttf);
this.exitStr.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor);
this.exitStr.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.62));
this.exitStr.color = cc.color.RED;
this.addChild(this.exitStr);
this.exitStr.visible = false;
this.yesBtn = new ccui.Button("YesBtn.png","YesBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
this.yesBtn.setScale(0.7 * GameCons.scaleFactor,0.7 * GameCons.scaleFactor);
this.yesBtn.x = cc.winSize.width * 0.42;
this.yesBtn.y = confirmHeight;
this.yesBtn.addTouchEventListener(this.yesQuit, this);
this.addChild(this.yesBtn);
this.yesBtn.visible = false;
this.noBtn = new ccui.Button("NoBtn.png","NoBtnDwn.png","",ccui.Widget.PLIST_TEXTURE);
this.noBtn.setScale(0.7 * GameCons.scaleFactor,0.7 * GameCons.scaleFactor);
this.noBtn.x = cc.winSize.width * 0.55;
this.noBtn.y = confirmHeight;
this.noBtn.addTouchEventListener(this.noQuit, this);
this.addChild(this.noBtn);
this.noBtn.visible = false;
this.confirmLabel = new cc.LabelBMFont("Confirm", res.menuFont_ttf);
this.confirmLabel.setScale(0.6 * GameCons.scaleFactor,0.6 * GameCons.scaleFactor);
if(GameCons.scaleFactor == 1)
this.confirmLabel.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.85));
else if(GameCons.scaleFactor == 2)
this.confirmLabel.setPosition(cc.p(cc.winSize.width * 0.5, cc.winSize.height * 0.81));
this.confirmLabel.color = cc.color.RED;
this.addChild(this.confirmLabel);
this.confirmLabel.visible = false;
if(GameCons.currLevel == 0 || GameCons.currLevel == 1 || GameCons.currLevel == 2)
GameCons.levelLocks[GameCons.currLevel + 1].level = 1;
cc.audioEngine.stopMusic();
cc.audioEngine.playMusic(res.menuMusic_mp3, false);
},
setConfirm:function()
{
this.quitBtn.visible = false;
this.nextBtn.visible = false;
this.restartBtn.visible = false;
this.fbBtn.visible = false;
this.yesBtn.visible = true;
this.whiteBg.visible = true;
this.noBtn.visible = true;
this.exitStr.visible = true;
this.confirmBg.visible = true;
this.confirmLabel.visible = true;
},
noPressed:function()
{
this.quitBtn.visible = true;
this.nextBtn.visible = true;
this.restartBtn.visible = true;
this.fbBtn.visible = true;
this.yesBtn.visible = false;
this.whiteBg.visible = false;
this.noBtn.visible = false;
this.exitStr.visible = false;
this.confirmBg.visible = false;
this.confirmLabel.visible = false;
},
fbShare:function(sender,type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
var ten = 10;
var info = {
"dialog": "shareLink",
"link": "http://www.cocos2d-x.org",
"name": "Level Complete",
"description": 'I completed level' + " " + (GameCons.currLevel + 1) + ' ' + 'In : ' + GameCons.levelTime + " " + 'Seconds',
"picture": "http://files.cocos2d-x.org/images/orgsite/logo.png"
};
var facebook = plugin.FacebookAgent.getInstance();
facebook.dialog(info, function (code, response) {
if(code == plugin.FacebookAgent.CODE_SUCCEED){
// Succeed
} else {
cc.log("Sharing failed, error #" + code + ": " + response);
}
});
break;
break;
}
},
noQuit:function(sender,type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
cc.audioEngine.playEffect(res.buttonClick_mp3);
this.noPressed();
break;
break;
}
},
yesQuit:function(sender,type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
cc.audioEngine.playEffect(res.buttonClick_mp3);
this.onQuitPressed();
break;
break;
}
},
checkStars:function()
{
if(GameCons.levelStars[GameCons.currLevel].stars < this.numOfStars)
{
GameCons.levelStars[GameCons.currLevel].stars = this.numOfStars;
//uses Localstroage to save how many stars you have recived
//this.saveStars();
}
},
saveStars:function()
{
var ls = cc.sys.localStorage;
var key = "levelStars";
for(var i = 0; i < GameCons.levelStars.length; i++)
ls.setItem(key + i, GameCons.levelStars[i].stars);
},
setStars:function()
{
var stars="";
var stars2 ="";
var stars3 ="";
if(this.numOfStars == 3)
{
stars = "#StarBig.png";
stars2 = "#StarBig.png";
stars3 = "#StarBig.png";
}
else if(this.numOfStars == 2)
{
stars = "#darkStar.png"
stars2 = "#StarBig.png";
stars3 = "#StarBig.png";
}
else if(this.numOfStars == 1)
{
stars = "#darkStar.png"
stars2 = "#darkStar.png"
stars3 = "#StarBig.png";
}
if(GameCons.scaleFactor == 1)
var starHeight = cc.winSize.height * 0.68;
else if(GameCons.scaleFactor == 2)
var starHeight = cc.winSize.height * 0.65;
var star = new cc.Sprite(stars);
if(GameCons.scaleFactor == 1)
star.setPositionX(cc.winSize.width * 0.655);
else if(GameCons.scaleFactor == 2)
star.setPositionX(cc.winSize.width * 0.67);
star.setPositionY(starHeight);
star.setOpacity(0);
star.setScale(2.5);
this.addChild(star);
var star2 = new cc.Sprite(stars2);
star2.setPositionX(cc.winSize.width * 0.495);
star2.setPositionY(starHeight);
star2.setOpacity(0);
star2.setScale(2.5);
this.addChild(star2);
var star3 = new cc.Sprite(stars3);
if(GameCons.scaleFactor == 1)
star3.setPositionX(cc.winSize.width * 0.33);
else if(GameCons.scaleFactor == 2)
star3.setPositionX(cc.winSize.width * 0.315);
star3.setPositionY(starHeight);
star3.setOpacity(0);
star3.setScale(2.5);
this.addChild(star3);
var scaleAction = cc.scaleTo(1, 1, 1);
var fadeIn = cc.FadeIn.create(1.0);
var playSound = cc.callFunc(this.playRewardSound,this);
if(this.numOfStars == 3)
{
star3.runAction(cc.Sequence(cc.delayTime(1),fadeIn,playSound,scaleAction));
star2.runAction(cc.Sequence(cc.delayTime(2),fadeIn,playSound,scaleAction));
star.runAction(cc.Sequence(cc.delayTime(3),fadeIn,playSound,scaleAction));
}
if(this.numOfStars == 2)
{
star3.runAction(cc.Sequence(cc.delayTime(1),fadeIn,playSound,scaleAction));
star2.runAction(cc.Sequence(cc.delayTime(2),fadeIn,playSound,scaleAction));
star.setScale(0.3, 0.3);
star.setOpacity(100);
}
else if(this.numOfStars == 1)
{
star3.runAction(cc.Sequence(cc.delayTime(1),fadeIn,playSound,scaleAction));
star2.setScale(0.3, 0.3);
star2.setOpacity(100);
star.setScale(0.3, 0.3);
star.setOpacity(100);
}
},
playRewardSound:function()
{
cc.audioEngine.playEffect(res.starRewardSnd_mp3);
},
getNumOfStars:function()
{
if(GameCons.levelTime < GameCons.starTimes[GameCons.currLevel].three)
this.numOfStars = 3;
else if(GameCons.levelTime < GameCons.starTimes[GameCons.currLevel].two)
this.numOfStars = 2;
else
this.numOfStars = 1;
},
touchResume: function(sender, type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
cc.audioEngine.playEffect(res.buttonClick_mp3);
this.resume();
break;
break;
}
},
nextLevel:function(sender,type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
cc.audioEngine.playEffect(res.buttonClick_mp3);
this.loadNextLevel();
break;
break;
}
},
touchQuit: function(sender, type)
{
switch (type)
{
case ccui.Widget.TOUCH_ENDED:
cc.audioEngine.playEffect(res.buttonClick_mp3);
this.setConfirm();
break;
break;
}
},
loadNextLevel:function()
{
INIT_PAUSE = false;
INIT_TUT = false;
INIT_END = false;
switch(GameCons.currLevel)
{
case 0:
cc.director.runScene(new cc.TransitionFade(1.5, new gameScene()));
break;
case 1:
GameCons.canMove = false;
cc.director.runScene(new cc.TransitionFade(1.5, new gameSceneLvl2()))
break;
case 2:
GameCons.canMove = false;
cc.director.runScene(new cc.TransitionFade(1.5, new gameSceneLvl3()));
break;
case 3:
GameCons.canMove = false;
cc.director.runScene(new cc.TransitionFade(1.5, new LevelSelectScene()));
break;
break;
}
},
resume:function()
{
INIT_PAUSE = false;
INIT_TUT = false;
INIT_END = false;
INIT_LEVEL2 = false;
INIT_LEVEL3 = false;
switch(GameCons.currLevel)
{
case 0:
GameCons.canMove = true;
cc.director.runScene(new cc.TransitionFade(1.5, new tutScene()));
break;
case 1:
cc.director.runScene(new cc.TransitionFade(1.5, new gameScene()))
break;
case 2:
cc.director.runScene(new cc.TransitionFade(1.5, new gameSceneLvl2()));
break;
case 3:
cc.director.runScene(new cc.TransitionFade(1.5, new gameSceneLvl3()));
break;
}
},
onQuitPressed:function()
{
INIT_TUT = false;
INIT_END = false;
cc.director.runScene(new cc.TransitionFade(1.5, new MainMenuScene()));
},
});
var EndScene = cc.Scene.extend({
onEnter:function ()
{
this._super();
if (INIT_END == false)
{
INIT_END = true;
var layer = new EndMenu();
this.addChild(layer);
}
}
});