diff --git a/cocos2d-win32.vc2008.sln b/cocos2d-win32.vc2008.sln index b0a8df1fed..dcf4b964e2 100644 --- a/cocos2d-win32.vc2008.sln +++ b/cocos2d-win32.vc2008.sln @@ -55,14 +55,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestLua", "samples\TestLua\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MoonWarriors", "samples\MoonWarriors\proj.win32\MoonWarriors.vcproj", "{A0EA54FA-6F12-45EC-AD5C-D139AA3CD528}" ProjectSection(ProjectDependencies) = postProject + {21B2C324-891F-48EA-AD1A-5AE13DE12E28} = {21B2C324-891F-48EA-AD1A-5AE13DE12E28} {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} EndProjectSection EndProject Global - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 Release|Win32 = Release|Win32 @@ -120,4 +118,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection EndGlobal diff --git a/samples/MoonWarriors/Resources/js/AboutLayer.js b/samples/MoonWarriors/Resources/js/AboutLayer.js index 4d188d335a..fc609895b7 100644 --- a/samples/MoonWarriors/Resources/js/AboutLayer.js +++ b/samples/MoonWarriors/Resources/js/AboutLayer.js @@ -11,27 +11,26 @@ var AboutLayer = cc.Layer.extend({ var cacheImage = cc.TextureCache.getInstance().addImage(s_menuTitle); var title = cc.Sprite.createWithTexture(cacheImage, cc.rect(0, 36, 100, 34)); - title.setPosition(cc.p(winSize.width / 2, winSize.height - 60)); + title.setPosition( winSize.width / 2, winSize.height - 60 ); this.addChild(title); // There is a bug in LabelTTF native. Apparently it fails with some unicode chars. -// var about = cc.LabelTTF.create(" This showcase utilizes many features from Cocos2d-html5 engine, including: Parallax background, tilemap, actions, ease, frame animation, schedule, Labels, keyboard Dispatcher, Scene Transition. \n Art and audio is copyrighted by Enigmata Genus Revenge, you may not use any copyrigted material without permission. This showcase is licensed under GPL. \n \n Programmer: \n Shengxiang Chen (陈升想) \n Dingping Lv (吕定平) \n Effects animation: Hao Wu(吴昊)\n Quality Assurance: Sean Lin(林顺)", "Arial", 14, cc.size(winSize.width * 0.85, 100), cc.TEXT_ALIGNMENT_LEFT ); - var about = cc.LabelTTF.create(" This showcase utilizes many features from Cocos2d-html5 engine, including: Parallax background, tilemap, actions, ease, frame animation, schedule, Labels, keyboard Dispatcher, Scene Transition. \n Art and audio is copyrighted by Enigmata Genus Revenge, you may not use any copyrigted material without permission. This showcase is licensed under GPL. \n\nProgrammer: \n Shengxiang Chen\n Dingping Lv \n Effects animation: Hao Wu\n Quality Assurance: Sean Lin", "Arial", 14, cc.size(winSize.width * 0.85, 320), cc.TEXT_ALIGNMENT_LEFT ); - about.setPosition(cc.p(winSize.width / 2, winSize.height/2 -20) ); - about.setAnchorPoint( cc.p(0.5, 0.5)); + var about = cc.LabelTTF.create(" This showcase utilizes many features from Cocos2d-html5 engine, including: Parallax background, tilemap, actions, ease, frame animation, schedule, Labels, keyboard Dispatcher, Scene Transition. \n Art and audio is copyrighted by Enigmata Genus Revenge, you may not use any copyrigted material without permission. This showcase is licensed under GPL. \n \n Programmer: \n Shengxiang Chen (陈升想) \n Dingping Lv (吕定平) \n Effects animation: Hao Wu(吴昊)\n Quality Assurance: Sean Lin(林顺)", "Arial", 14, cc.size(winSize.width * 0.85, 320), cc.TEXT_ALIGNMENT_LEFT ); + about.setPosition(winSize.width / 2, winSize.height/2 -20 ); + about.setAnchorPoint( cc.p(0.5, 0.5) ); this.addChild(about); var label = cc.LabelTTF.create("Go back", "Arial", 14); - var back = cc.MenuItemLabel.create(label, this, this.backCallback); + var back = cc.MenuItemLabel.create(label, this.onBackCallback); var menu = cc.Menu.create(back); - menu.setPosition(cc.p(winSize.width / 2, 40)); + menu.setPosition( winSize.width / 2, 40); this.addChild(menu); bRet = true; } return bRet; }, - backCallback:function (pSender) { + onBackCallback:function (pSender) { var scene = cc.Scene.create(); scene.addChild(SysMenu.create()); cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene)); diff --git a/samples/MoonWarriors/Resources/js/Bullet.js b/samples/MoonWarriors/Resources/js/Bullet.js index 81199494bd..3c74045eee 100644 --- a/samples/MoonWarriors/Resources/js/Bullet.js +++ b/samples/MoonWarriors/Resources/js/Bullet.js @@ -47,10 +47,10 @@ var Bullet = cc.Sprite.extend({ this.getParent().addChild(explode,9999); cc.ArrayRemoveObject(MW.CONTAINER.ENEMY_BULLETS,this); cc.ArrayRemoveObject(MW.CONTAINER.PLAYER_BULLETS,this); - this.removeFromParentAndCleanup(true); + this.removeFromParent(); - var removeExplode = cc.CallFunc.create(explode, function(sender) { - explode.removeFromParentAndCleanup(true); + var removeExplode = cc.CallFunc.create(function(sender) { + explode.removeFromParent(); }); explode.runAction(cc.ScaleBy.create(0.3, 2,2)); diff --git a/samples/MoonWarriors/Resources/js/Effect.js b/samples/MoonWarriors/Resources/js/Effect.js index faaa03c491..1b1e2041f4 100644 --- a/samples/MoonWarriors/Resources/js/Effect.js +++ b/samples/MoonWarriors/Resources/js/Effect.js @@ -3,7 +3,7 @@ var flareEffect = function (parent, target, callback) { flare.setBlendFunc(gl.SRC_ALPHA, gl.ONE); parent.addChild(flare, 10); flare.setOpacity(0); - flare.setPosition(cc.p(-30, 297)); + flare.setPosition(-30, 297); flare.setRotation(-120); flare.setScale(0.2); @@ -17,10 +17,10 @@ var flareEffect = function (parent, target, callback) { var rotateEase = cc.EaseExponentialOut.create(rotateAnim); var bigger = cc.ScaleTo.create(0.5, 1); - var onComplete = cc.CallFunc.create(target, callback); - var killflare = cc.CallFunc.create(flare, function () { + var onComplete = cc.CallFunc.create(callback, target); + var killflare = cc.CallFunc.create(function () { this.getParent().removeChild(this,true); - }); + }, flare); flare.runAction(cc.Sequence.create(opacityAnim, biggerEase, opacDim, killflare, onComplete)); flare.runAction(easeMove); flare.runAction(rotateEase); @@ -29,7 +29,7 @@ var flareEffect = function (parent, target, callback) { var removeFromParent = function( sprite ) { - sprite.removeFromParentAndCleanup( true ); + sprite.removeFromParent(); }; var spark = function (ccpoint, parent, scale, duration) { @@ -61,7 +61,7 @@ var spark = function (ccpoint, parent, scale, duration) { var right = cc.RotateBy.create(duration, 45); var scaleBy = cc.ScaleBy.create(duration, 3, 3); var fadeOut = cc.FadeOut.create(duration); - var remove = cc.CallFunc.create(this, removeFromParent ); + var remove = cc.CallFunc.create(removeFromParent, this); var seq = cc.Sequence.create( fadeOut, remove ); one.runAction(left); diff --git a/samples/MoonWarriors/Resources/js/Enemy.js b/samples/MoonWarriors/Resources/js/Enemy.js index e266118547..1477cd9df4 100644 --- a/samples/MoonWarriors/Resources/js/Enemy.js +++ b/samples/MoonWarriors/Resources/js/Enemy.js @@ -46,7 +46,7 @@ var Enemy = cc.Sprite.extend({ this.getParent().addChild(a); spark(this.getPosition(),this.getParent(), 1.2, 0.7); cc.ArrayRemoveObject(MW.CONTAINER.ENEMIES,this); - this.removeFromParentAndCleanup(true); + this.removeFromParent(); if(MW.SOUND){ cc.AudioEngine.getInstance().playEffect(s_explodeEffect); } @@ -56,7 +56,7 @@ var Enemy = cc.Sprite.extend({ var b = new Bullet(this.bulletSpeed, "W2.png", this.attackMode); MW.CONTAINER.ENEMY_BULLETS.push(b); this.getParent().addChild(b, b.zOrder, MW.UNIT_TAG.ENMEY_BULLET); - b.setPosition(cc.p(p.x, p.y - this.getContentSize().height * 0.2)); + b.setPosition(p.x, p.y - this.getContentSize().height * 0.2); }, hurt:function () { this._hurtColorLife = 2; diff --git a/samples/MoonWarriors/Resources/js/Explosion.js b/samples/MoonWarriors/Resources/js/Explosion.js index 8ccd225c5d..0470fd40a9 100644 --- a/samples/MoonWarriors/Resources/js/Explosion.js +++ b/samples/MoonWarriors/Resources/js/Explosion.js @@ -15,12 +15,12 @@ var Explosion = cc.Sprite.extend({ var animation = cc.AnimationCache.getInstance().getAnimation("Explosion"); this.runAction(cc.Sequence.create( cc.Animate.create(animation), - cc.CallFunc.create(this, this.destroy) + cc.CallFunc.create(this.destroy, this) )); this.setBlendFunc(gl.SRC_ALPHA, gl.ONE); }, destroy:function () { - this.getParent().removeChild(this,true); + this.getParent().removeChild(this); } }); diff --git a/samples/MoonWarriors/Resources/js/GameControlMenu.js b/samples/MoonWarriors/Resources/js/GameControlMenu.js index 3fcdac736e..a07e2c01ae 100644 --- a/samples/MoonWarriors/Resources/js/GameControlMenu.js +++ b/samples/MoonWarriors/Resources/js/GameControlMenu.js @@ -8,18 +8,18 @@ var GameControlMenu = cc.Layer.extend({ if (this._super()) { cc.MenuItemFont.setFontSize(18); cc.MenuItemFont.setFontName("Arial"); - var systemMenu = cc.MenuItemFont.create("Main Menu", this, this.sysMenu); + var systemMenu = cc.MenuItemFont.create("Main Menu", this.onSysMenu); var menu = cc.Menu.create(systemMenu); - menu.setPosition(cc.p(0, 0)); + menu.setPosition(0, 0); systemMenu.setAnchorPoint(cc.p(0, 0)); - systemMenu.setPosition(cc.p(winSize.width-95, 5)); + systemMenu.setPosition(winSize.width-95, 5); this.addChild(menu, 1, 2); bRet = true; } return bRet; }, - sysMenu:function (pSender) { + onSysMenu:function (pSender) { var scene = cc.Scene.create(); scene.addChild(SysMenu.create()); cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2,scene)); diff --git a/samples/MoonWarriors/Resources/js/GameLayer.js b/samples/MoonWarriors/Resources/js/GameLayer.js index 60ee0ba738..218035e105 100644 --- a/samples/MoonWarriors/Resources/js/GameLayer.js +++ b/samples/MoonWarriors/Resources/js/GameLayer.js @@ -30,6 +30,7 @@ var GameLayer = cc.Layer.extend({ }, init:function () { var bRet = false; + cc.log("GameLayer init"); if (this._super()) { // reset global values @@ -52,18 +53,18 @@ var GameLayer = cc.Layer.extend({ this.lbScore.setAnchorPoint( cc.p(1,0) ); this.lbScore.setAlignment( cc.TEXT_ALIGNMENT_RIGHT ); this.addChild(this.lbScore, 1000); - this.lbScore.setPosition(cc.p(winSize.width - 5 , winSize.height - 30)); + this.lbScore.setPosition(winSize.width - 5 , winSize.height - 30); // ship life var shipTexture = cc.TextureCache.getInstance().addImage(s_ship01); var life = cc.Sprite.createWithTexture(shipTexture, cc.rect(0, 0, 60, 38)); life.setScale(0.6); - life.setPosition(cc.p(30, 460)); + life.setPosition(30, 460); this.addChild(life, 1, 5); // ship Life count this._lbLife = cc.LabelTTF.create("0", "Arial", 20); - this._lbLife.setPosition(cc.p(60, 463)); + this._lbLife.setPosition(60, 463); this._lbLife.setColor(cc.RED); this.addChild(this._lbLife, 1000); @@ -75,7 +76,7 @@ var GameLayer = cc.Layer.extend({ var t = cc.config.deviceType; if( t == 'browser' ) { - this.setTouchEnabled(true); + this.setMouseEnabled(true); this.setKeyboardEnabled(true); } else if( t == 'desktop' ) { this.setMouseEnabled(true); @@ -88,7 +89,7 @@ var GameLayer = cc.Layer.extend({ this.schedule(this.scoreCounter, 1); if (MW.SOUND) { - cc.AudioEngine.getInstance().playBackgroundMusic(s_bgMusic, true); + cc.AudioEngine.getInstance().playMusic(s_bgMusic, true); } bRet = true; @@ -215,7 +216,7 @@ var GameLayer = cc.Layer.extend({ this._ship = null; this.runAction(cc.Sequence.create( cc.DelayTime.create(0.2), - cc.CallFunc.create(this, this.onGameOver))); + cc.CallFunc.create(this.onGameOver, this))); } }, updateUI:function () { @@ -262,7 +263,7 @@ var GameLayer = cc.Layer.extend({ this._backSkyRe = cc.Sprite.create(s_bg01); this._backSkyRe.setAnchorPoint(cc.p(0, 0)); this.addChild(this._backSkyRe, -10); - this._backSkyRe.setPosition(cc.p(0, winSize.height)); + this._backSkyRe.setPosition(0, winSize.height); this._isBackSkyReload = true; } this._backSkyRe.runAction(cc.MoveBy.create(3, cc.p(0, -48))); @@ -279,7 +280,7 @@ var GameLayer = cc.Layer.extend({ if (!this._isBackTileReload) { this._backTileMapRe = cc.TMXTiledMap.create(s_level01); this.addChild(this._backTileMapRe, -9); - this._backTileMapRe.setPosition(cc.p(0, winSize.height)); + this._backTileMapRe.setPosition(0, winSize.height); this._isBackTileReload = true; } this._backTileMapRe.runAction(cc.MoveBy.create(3, cc.p(0, -200))); diff --git a/samples/MoonWarriors/Resources/js/GameOver.js b/samples/MoonWarriors/Resources/js/GameOver.js index 7fcf87c645..a047837254 100644 --- a/samples/MoonWarriors/Resources/js/GameOver.js +++ b/samples/MoonWarriors/Resources/js/GameOver.js @@ -14,7 +14,7 @@ var GameOver = cc.Layer.extend({ var logo = cc.Sprite.create(s_gameOver); logo.setAnchorPoint(cc.p(0,0)); - logo.setPosition(cc.p(0,300)); + logo.setPosition(0,300); this.addChild(logo,10,1); var playAgainNormal = cc.Sprite.create(s_menu, cc.rect(378, 0, 126, 33)); @@ -22,37 +22,37 @@ var GameOver = cc.Layer.extend({ var playAgainDisabled = cc.Sprite.create(s_menu, cc.rect(378, 33 * 2, 126, 33)); var cocos2dhtml5 = cc.Sprite.create(s_cocos2dhtml5); - cocos2dhtml5.setPosition(cc.p(160,150)); + cocos2dhtml5.setPosition(160,150); this.addChild(cocos2dhtml5,10); - var playAgain = cc.MenuItemSprite.create(playAgainNormal, playAgainSelected, playAgainDisabled, this, function(){ + var playAgain = cc.MenuItemSprite.create(playAgainNormal, playAgainSelected, playAgainDisabled, function(){ flareEffect(this,this,this.onPlayAgain); - }); + }.bind(this) ); var menu = cc.Menu.create(playAgain); this.addChild(menu, 1, 2); - menu.setPosition(cc.p(winSize.width / 2, 220)); + menu.setPosition(winSize.width / 2, 220); var lbScore = cc.LabelTTF.create("Your Score:"+MW.SCORE,"Arial Bold",16); - lbScore.setPosition(cc.p(160,280)); + lbScore.setPosition(160,280); lbScore.setColor(cc.c3b(250,179,0)); this.addChild(lbScore,10); var b1 = cc.LabelTTF.create("Download Cocos2d-html5","Arial",14); var b2 = cc.LabelTTF.create("Download This Sample","Arial",14); - var menu1 = cc.MenuItemLabel.create(b1,this,function(){ + var menu1 = cc.MenuItemLabel.create(b1,function(){ window.location.href = "http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d-html5"; }); - var menu2 = cc.MenuItemLabel.create(b2,this,function(){ + var menu2 = cc.MenuItemLabel.create(b2,function(){ window.location.href = "https://github.com/ShengxiangChen/MoonWarriors"; }); var cocos2dMenu = cc.Menu.create(menu1,menu2); cocos2dMenu.alignItemsVerticallyWithPadding(10); - cocos2dMenu.setPosition(cc.p(160,80)); + cocos2dMenu.setPosition(160,80); this.addChild(cocos2dMenu); if(MW.SOUND){ - cc.AudioEngine.getInstance().playBackgroundMusic(s_mainMainMusic); + cc.AudioEngine.getInstance().playMusic(s_mainMainMusic); } bRet = true; diff --git a/samples/MoonWarriors/Resources/js/LevelManager.js b/samples/MoonWarriors/Resources/js/LevelManager.js index 6866d7412f..fccbd1e0c3 100644 --- a/samples/MoonWarriors/Resources/js/LevelManager.js +++ b/samples/MoonWarriors/Resources/js/LevelManager.js @@ -57,7 +57,7 @@ var LevelManager = cc.Class.extend({ var enemypos = cc.p( 80 + (winSize.width - 160) * Math.random(), winSize.height); var enemycs = addEnemy.getContentSize(); addEnemy.setPosition( enemypos ); - + var offset, tmpAction; var a0=0; @@ -75,13 +75,13 @@ var LevelManager = cc.Class.extend({ offset = cc.p(0, -100 - 200 * Math.random()); a0 = cc.MoveBy.create(0.5, offset); a1 = cc.MoveBy.create(1, cc.p(-50 - 100 * Math.random(), 0)); - var onComplete = cc.CallFunc.create(addEnemy, function (pSender) { + var onComplete = cc.CallFunc.create(function (pSender) { var a2 = cc.DelayTime.create(1); var a3 = cc.MoveBy.create(1, cc.p(100 + 100 * Math.random(), 0)); pSender.runAction(cc.RepeatForever.create( cc.Sequence.create(a2, a3, a2.copy(), a3.reverse()) )); - }); + }.bind(addEnemy) ); tmpAction = cc.Sequence.create(a0, a1, onComplete); break; case MW.ENEMY_MOVE_TYPE.OVERLAP: diff --git a/samples/MoonWarriors/Resources/js/SettingsLayer.js b/samples/MoonWarriors/Resources/js/SettingsLayer.js index 4f8b545311..b4694bed26 100644 --- a/samples/MoonWarriors/Resources/js/SettingsLayer.js +++ b/samples/MoonWarriors/Resources/js/SettingsLayer.js @@ -11,7 +11,7 @@ var SettingsLayer = cc.Layer.extend({ var cacheImage = cc.TextureCache.getInstance().addImage(s_menuTitle); var title = cc.Sprite.createWithTexture(cacheImage, cc.rect(0, 0, 134, 34)); - title.setPosition(cc.p(winSize.width / 2, winSize.height - 120)); + title.setPosition(winSize.width / 2, winSize.height - 120); this.addChild(title); @@ -25,7 +25,7 @@ var SettingsLayer = cc.Layer.extend({ var item1 = cc.MenuItemToggle.create( cc.MenuItemFont.create("On"), cc.MenuItemFont.create("Off") ); - item1.setCallback(this, this.soundControl ); + item1.setCallback(this.onSoundControl ); cc.MenuItemFont.setFontName("Arial"); cc.MenuItemFont.setFontSize(18); @@ -38,13 +38,13 @@ var SettingsLayer = cc.Layer.extend({ cc.MenuItemFont.create("Easy"), cc.MenuItemFont.create("Normal"), cc.MenuItemFont.create("Hard")); - item2.setCallback( this, this.modeControl ); + item2.setCallback( this.onModeControl ); cc.MenuItemFont.setFontName("Arial"); cc.MenuItemFont.setFontSize(26); var label = cc.LabelTTF.create("Go back", "Arial", 20); - var back = cc.MenuItemLabel.create(label, this, this.backCallback); + var back = cc.MenuItemLabel.create(label, this.onBackCallback); back.setScale(0.8); var menu = cc.Menu.create(title1, title2, item1, item2, back); @@ -61,18 +61,18 @@ var SettingsLayer = cc.Layer.extend({ return bRet; }, - backCallback:function (pSender) { + onBackCallback:function (pSender) { var scene = cc.Scene.create(); scene.addChild(SysMenu.create()); cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene)); }, - soundControl:function(){ + onSoundControl:function(){ MW.SOUND = MW.SOUND ? false : true; if(!MW.SOUND){ - cc.AudioEngine.getInstance().stopBackgroundMusic(); + cc.AudioEngine.getInstance().stopMusic(); } }, - modeControl:function(){ + onModeControl:function(){ } }); diff --git a/samples/MoonWarriors/Resources/js/Ship.js b/samples/MoonWarriors/Resources/js/Ship.js index 84aa6342db..cd4041395b 100644 --- a/samples/MoonWarriors/Resources/js/Ship.js +++ b/samples/MoonWarriors/Resources/js/Ship.js @@ -42,15 +42,15 @@ var Ship = cc.Sprite.extend({ var ghostSprite = cc.Sprite.createWithTexture(shipTexture, cc.rect(0, 45, 60, 38)); ghostSprite.setBlendFunc(gl.SRC_ALPHA, gl.ONE); ghostSprite.setScale(8); - ghostSprite.setPosition(cc.p(this.getContentSize().width / 2, 12)); + ghostSprite.setPosition(this.getContentSize().width / 2, 12); this.addChild(ghostSprite, 3000, 99999); ghostSprite.runAction(cc.ScaleTo.create(0.5, 1, 1)); var blinks = cc.Blink.create(3, 9); - var makeBeAttack = cc.CallFunc.create(this, function (t) { + var makeBeAttack = cc.CallFunc.create(function (t) { t.canBeAttack = true; t.setVisible(true); t.removeChild(ghostSprite,true); - }); + }.bind(this)); this.runAction(cc.Sequence.create(cc.DelayTime.create(0.5), blinks, makeBeAttack)); }, update:function (dt) { @@ -95,12 +95,12 @@ var Ship = cc.Sprite.extend({ var a = new Bullet(this.bulletSpeed, "W1.png", MW.ENEMY_MOVE_TYPE.NORMAL); MW.CONTAINER.PLAYER_BULLETS.push(a); this.getParent().addChild(a, a.zOrder, MW.UNIT_TAG.PLAYER_BULLET); - a.setPosition(cc.p(p.x + offset, p.y + 3 + cs.height * 0.3)); + a.setPosition(p.x + offset, p.y + 3 + cs.height * 0.3); var b = new Bullet(this.bulletSpeed, "W1.png", MW.ENEMY_MOVE_TYPE.NORMAL); MW.CONTAINER.PLAYER_BULLETS.push(b); this.getParent().addChild(b, b.zOrder, MW.UNIT_TAG.PLAYER_BULLET); - b.setPosition(cc.p(p.x - offset, p.y + 3 + cs.height * 0.3)); + b.setPosition(p.x - offset, p.y + 3 + cs.height * 0.3); }, destroy:function () { MW.LIFE--; diff --git a/samples/MoonWarriors/Resources/js/SysMenu.js b/samples/MoonWarriors/Resources/js/SysMenu.js index a265636363..be2546bcf0 100644 --- a/samples/MoonWarriors/Resources/js/SysMenu.js +++ b/samples/MoonWarriors/Resources/js/SysMenu.js @@ -16,7 +16,7 @@ var SysMenu = cc.Layer.extend({ var logo = cc.Sprite.create(s_logo); logo.setAnchorPoint(cc.p(0, 0)); - logo.setPosition(cc.p(0, 250)); + logo.setPosition(0, 250); this.addChild(logo, 10, 1); var newGameNormal = cc.Sprite.create(s_menu, cc.rect(0, 0, 126, 33)); @@ -31,17 +31,22 @@ var SysMenu = cc.Layer.extend({ var aboutSelected = cc.Sprite.create(s_menu, cc.rect(252, 33, 126, 33)); var aboutDisabled = cc.Sprite.create(s_menu, cc.rect(252, 33 * 2, 126, 33)); - var newGame = cc.MenuItemSprite.create(newGameNormal, newGameSelected, newGameDisabled, this, function () { + cc.log("SysMenu init"); + + var newGame = cc.MenuItemSprite.create(newGameNormal, newGameSelected, newGameDisabled, function () { + cc.log("newGame callback1"); this.onButtonEffect(); + cc.log("newGame callback2"); flareEffect(this, this, this.onNewGame); - }); - var gameSettings = cc.MenuItemSprite.create(gameSettingsNormal, gameSettingsSelected, gameSettingsDisabled, this, this.onSettings); - var about = cc.MenuItemSprite.create(aboutNormal, aboutSelected, aboutDisabled, this, this.onAbout); + cc.log("newGame callback3"); + }.bind(this)); + var gameSettings = cc.MenuItemSprite.create(gameSettingsNormal, gameSettingsSelected, gameSettingsDisabled, this.onSettings, this); + var about = cc.MenuItemSprite.create(aboutNormal, aboutSelected, aboutDisabled, this.onAbout, this); var menu = cc.Menu.create(newGame, gameSettings, about); menu.alignItemsVerticallyWithPadding(10); this.addChild(menu, 1, 2); - menu.setPosition(cc.p(winSize.width / 2, winSize.height / 2 - 80)); + menu.setPosition(winSize.width / 2, winSize.height / 2 - 80); this.schedule(this.update, 0.1); var tmp = cc.TextureCache.getInstance().addImage(s_ship01); @@ -52,8 +57,8 @@ var SysMenu = cc.Layer.extend({ this._ship.runAction(cc.MoveBy.create(2, cc.p(Math.random() * winSize.width, pos.y + winSize.height + 100))); if (MW.SOUND) { - cc.AudioEngine.getInstance().setBackgroundMusicVolume(0.7); - cc.AudioEngine.getInstance().playBackgroundMusic(s_mainMainMusic, true); + cc.AudioEngine.getInstance().setMusicVolume(0.7); + cc.AudioEngine.getInstance().playMusic(s_mainMainMusic, true); } bRet = true; @@ -61,10 +66,14 @@ var SysMenu = cc.Layer.extend({ return bRet; }, onNewGame:function (pSender) { + cc.log("onNewGame 1"); var scene = cc.Scene.create(); scene.addChild(GameLayer.create()); + cc.log("onNewGame 2"); scene.addChild(GameControlMenu.create()); + cc.log("onNewGame 3"); cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, scene)); + cc.log("onNewGame 4"); }, onSettings:function (pSender) { this.onButtonEffect(); diff --git a/samples/MoonWarriors/Resources/js/helper/jsb_constants.js b/samples/MoonWarriors/Resources/js/helper/jsb_constants.js index d744f521bf..cbedb7354b 100644 --- a/samples/MoonWarriors/Resources/js/helper/jsb_constants.js +++ b/samples/MoonWarriors/Resources/js/helper/jsb_constants.js @@ -1,475 +1,12 @@ -require('js/helper/jsb_constants_gl.js'); -// cocos2d Helper - -cc.c3 = cc.c3 || function (r, g, b) { - return {r: r, g: g, b: b}; -}; - -cc.c3b = cc.c3; - -cc.c4 = cc.c4 || function (r, g, b, o) { - return {r: r, g: g, b: b, a: o}; -}; - -cc.c4b = cc.c4; - -cc.c4f = cc.c4f || function (r, g, b, o) { - return {r: r, g: g, b: b, a: o}; -}; - -cc.p = cc.p || function( x, y ) -{ - return {x:x, y:y}; -}; +// +// Javascript Bindigns helper file +// cc.g = cc.g || cc.p; cc.log = cc.log || log; -// -// cocos2d constants -// -cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0; -cc.TEXTURE_PIXELFORMAT_RGB888 = 1; -cc.TEXTURE_PIXELFORMAT_RGB565 = 2; -cc.TEXTURE_PIXELFORMAT_A8 = 3; -cc.TEXTURE_PIXELFORMAT_I8 = 4; -cc.TEXTURE_PIXELFORMAT_AI88 = 5; -cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6; -cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7; -cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8; -cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9; -cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888; - -cc.TEXT_ALIGNMENT_LEFT = 0; -cc.TEXT_ALIGNMENT_CENTER = 1; -cc.TEXT_ALIGNMENT_RIGHT = 2; - -cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0; -cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1; -cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2; - -cc.IMAGE_FORMAT_JPEG = 0; -cc.IMAGE_FORMAT_PNG = 0; - -cc.PROGRESS_TIMER_TYPE_RADIAL = 0; -cc.PROGRESS_TIMER_TYPE_BAR = 1; - -cc.PARTICLE_TYPE_FREE = 0; -cc.PARTICLE_TYPE_RELATIVE = 1; -cc.PARTICLE_TYPE_GROUPED = 2; -cc.PARTICLE_DURATION_INFINITY = -1; -cc.PARTICLE_MODE_GRAVITY = 0; -cc.PARTICLE_MODE_RADIUS = 1; -cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1; -cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1; - -cc.RED = cc.c3(255,0,0); -cc.GREEN = cc.c3(0,255,0); -cc.BLUE = cc.c3(0,0,255); -cc.BLACK = cc.c3(0,0,0); -cc.WHITE = cc.c3(255,255,255); - -cc.POINT_ZERO = {x:0, y:0}; - -cc._reuse_p0 = {x:0, y:0}; -cc._reuse_p1 = {x:0, y:0}; -cc._reuse_p_index = 0; -cc._reuse_color3b = cc.c3(255, 255, 255 ); -cc._reuse_color4b = cc.c4(255, 255, 255, 255 ); -cc._reuse_grid = cc.g(0,0); - -// dump config info, but only in debug mode -cc.dumpConfig = function() -{ - if( cc.config.debug ) { - for(var i in cc.config) - cc.log( i + " = " + cc.config[i] ); - } -}; - -// -// Point -// -cc._p = function( x, y ) -{ - if( cc._reuse_p_index === 0 ) { - cc._reuse_p0.x = x; - cc._reuse_p0.y = y; - cc._reuse_p_index = 1; - return cc._reuse_p0; - } else { - cc._reuse_p1.x = x; - cc._reuse_p1.y = y; - cc._reuse_p_index = 0; - return cc._reuse_p1; - } -}; - -cc._to_p = function( point ) -{ - return point; -}; - -cc._from_p = function( size ) -{ - return size; -}; - -// -// Grid -// -cc._g = function( x, y ) -{ - cc._reuse_grid.x = x; - cc._reuse_grid.y = y; - return cc._reuse_grid; -} - -// -// Color -// -// -// Color 3B -// -cc.c3b = function( r, g, b ) -{ - return {r:r, g:g, b:b }; -}; -cc._c3b = function( r, g, b ) -{ - cc._reuse_color3b.r = r; - cc._reuse_color3b.g = g; - cc._reuse_color3b.b = b; - return cc._reuse_color3b; -}; -// compatibility -cc.c3 = cc.c3b; -cc._c3 = cc._c3b; - -// -// Color 4B -// -cc.c4b = function( r, g, b, a ) -{ - return {r:r, g:g, b:b, a:a }; -}; -cc._c4b = function( r, g, b, a ) -{ - cc._reuse_color4b.r = r; - cc._reuse_color4b.g = g; - cc._reuse_color4b.b = b; - cc._reuse_color4b.a = a; - return cc._reuse_color4b; -}; -// compatibility -cc.c4 = cc.c4b; -cc._c4 = cc._c4b; - - -// -// Size -// -cc.size = function(w,h) -{ - return {width:w, height:h}; -} - -cc._to_size = function( size ) -{ - return size; -} - -cc._from_size = function( size ) -{ - return size; -} - -// -// Rect -// -cc.rect = function(x,y,w,h) -{ - return {x:x, y:y, width:w, height:h}; -} - -cc._to_rect = function( rect ) -{ - return rect; -} - -cc._from_rect = function( rect ) -{ - return rect; -} - -// XXX Should be done in native -cc.rectIntersectsRect = function( rectA, rectB ) -{ - var bool = ! ( rectA.x > rectB.x + rectB.width || - rectA.x + rectA.width < rectB.x || - rectA.y > rectB.y +rectB.height || - rectA.y + rectA.height < rectB.y ); - - return bool; -} - -// point functions -cc.pAdd = cc.pAdd || function (p1, p2) { - return {x: p1.x + p2.x, y: p1.y + p2.y}; -}; - -cc.pSub = cc.pSub || function (p1, p2) { - return {x: p1.x - p2.x, y: p1.y - p2.y}; -} - -cc.pMult = cc.pMult || function (p1, s) { - return {x: p1.x * s, y: p1.y * s}; -}; - -/** - * Calculates dot product of two points. - * @param {cc.Point} v1 - * @param {cc.Point} v2 - * @return {Number} - */ -cc.pDot = function (v1, v2) { - return v1.x * v2.x + v1.y * v2.y; -}; - -/** - * Calculates the square length of a cc.Point (not calling sqrt() ) - * @param {cc.Point} v - *@return {cc.pDot} - */ -cc.pLengthSQ = function (v) { - return cc.pDot(v, v); -}; - -/** - * Calculates distance between point an origin - * @param {cc.Point} v - * @return {Number} - */ -cc.pLength = function (v) { - return Math.sqrt(cc.pLengthSQ(v)); -}; - -/** - * Calculates the distance between two points - * @param {cc.Point} v1 - * @param {cc.Point} v2 - * @return {cc.pLength} - */ -cc.pDistance = function (v1, v2) { - return cc.pLength(cc.pSub(v1, v2)); -}; - -/** - * Clamp a value between from and to. - * @param {Number} value - * @param {Number} min_inclusive - * @param {Number} max_inclusive - * @return {Number} - */ -cc.clampf = function (value, min_inclusive, max_inclusive) { - if (min_inclusive > max_inclusive) { - var temp = min_inclusive; - min_inclusive = max_inclusive; - max_inclusive = temp; - } - return value < min_inclusive ? min_inclusive : value < max_inclusive ? value : max_inclusive; -}; - -/** - * Clamp a point between from and to. - * @param {Number} p - * @param {Number} min_inclusive - * @param {Number} max_inclusive - * @return {cc.Point} - */ -cc.pClamp = function (p, min_inclusive, max_inclusive) { - return cc.p(cc.clampf(p.x, min_inclusive.x, max_inclusive.x), cc.clampf(p.y, min_inclusive.y, max_inclusive.y)); -}; - -/** - * returns a random float between 0 and 1 - * @return {Number} - * @function - */ -cc.RANDOM_0_1 = function () { - return Math.random(); -}; - -/** - * Associates a base class with a native superclass - * @function - * @param {object} jsobj subclass - * @param {object} klass superclass - */ -cc.associateWithNative = function( jsobj, superclass ) { - var native = new superclass(); - __associateObjWithNative( jsobj, native ); -}; - -// -// Array: for cocos2d-hmtl5 compatibility -// -cc.ArrayRemoveObject = function (arr, delObj) { - for (var i = 0; i < arr.length; i++) { - if (arr[i] == delObj) { - arr.splice(i, 1); - } - } -}; - -// -// Google "subclasses" -// borrowed from closure library -// -var goog = goog || {}; // Check to see if already defined in current scope -goog.inherits = function (childCtor, parentCtor) { - /** @constructor */ - function tempCtor() {}; - tempCtor.prototype = parentCtor.prototype; - childCtor.superClass_ = parentCtor.prototype; - childCtor.prototype = new tempCtor(); - childCtor.prototype.constructor = childCtor; - - // Copy "static" method, but doesn't generate subclasses. -// for( var i in parentCtor ) { -// childCtor[ i ] = parentCtor[ i ]; -// } -}; -goog.base = function(me, opt_methodName, var_args) { - var caller = arguments.callee.caller; - if (caller.superClass_) { - // This is a constructor. Call the superclass constructor. - ret = caller.superClass_.constructor.apply( me, Array.prototype.slice.call(arguments, 1)); - - // XXX: SpiderMonkey bindings extensions -// __associateObjWithNative( me, ret ); - return ret; - } - - var args = Array.prototype.slice.call(arguments, 2); - var foundCaller = false; - for (var ctor = me.constructor; - ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) { - if (ctor.prototype[opt_methodName] === caller) { - foundCaller = true; - } else if (foundCaller) { - return ctor.prototype[opt_methodName].apply(me, args); - } - } - - // If we did not find the caller in the prototype chain, - // then one of two things happened: - // 1) The caller is an instance method. - // 2) This method was not called by the right caller. - if (me[opt_methodName] === caller) { - return me.constructor.prototype[opt_methodName].apply(me, args); - } else { - throw Error( - 'goog.base called from a method of one name ' + - 'to a method of a different name'); - } -}; - - -// -// Simple subclass -// - -cc.Class = function(){}; - -cc.Class.extend = function (prop) { - var _super = this.prototype; - - // Instantiate a base class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && fnTest.test(prop[name]) ? - (function (name, fn) { - return function () { - var tmp = this._super; - - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if (!initializing && this.ctor) - this.ctor.apply(this, arguments); - } - - // Populate our constructed prototype object - Class.prototype = prototype; - - // Enforce the constructor to be what we expect - Class.prototype.constructor = Class; - - // And make this class extendable - Class.extend = arguments.callee; - - return Class; -}; - -cc.Layer.extend = cc.Class.extend; -cc.Scene.extend = cc.Class.extend; -cc.LayerGradient.extend = cc.Class.extend; -cc.Sprite.extend = cc.Class.extend; -cc.MenuItemFont.extend = cc.Class.extend; - -// -// Chipmunk helpers -// -var cp = cp || {}; - -cp.v = cc.p; -cp._v = cc._p; -cp.vzero = cp.v(0,0); - -// -// OpenGL Helpers -// -var gl = gl || {}; -gl.NEAREST = 0x2600; -gl.LINEAR = 0x2601; -gl.REPEAT = 0x2901; -gl.CLAMP_TO_EDGE = 0x812F; -gl.CLAMP_TO_BORDER = 0x812D; -gl.LINEAR_MIPMAP_NEAREST = 0x2701; -gl.NEAREST_MIPMAP_NEAREST = 0x2700; -gl.ZERO = 0; -gl.ONE = 1; -gl.SRC_COLOR = 0x0300; -gl.ONE_MINUS_SRC_COLOR = 0x0301; -gl.SRC_ALPHA = 0x0302; -gl.ONE_MINUS_SRC_ALPHA = 0x0303; -gl.DST_ALPHA = 0x0304; -gl.ONE_MINUS_DST_ALPHA = 0x0305; -gl.DST_COLOR = 0x0306; -gl.ONE_MINUS_DST_COLOR = 0x0307; -gl.SRC_ALPHA_SATURATE = 0x0308; - +// DO NOT ALTER THE ORDER +require('js/helper/jsb_constants_cocos2d.js'); +// require('jsb_constants_chipmunk.js'); +require('js/helper/jsb_constants_gl.js'); +require('js/helper/jsb_constants_cocosbuilder.js'); diff --git a/samples/MoonWarriors/Resources/js/helper/jsb_constants_chipmunk.js b/samples/MoonWarriors/Resources/js/helper/jsb_constants_chipmunk.js new file mode 100644 index 0000000000..724c6afa36 --- /dev/null +++ b/samples/MoonWarriors/Resources/js/helper/jsb_constants_chipmunk.js @@ -0,0 +1,253 @@ +// +// Chipmunk defines +// + +cp.v = cc.p; +cp._v = cc._p; +cp.vzero = cp.v(0,0); + +// Vector: Compatibility with Chipmunk-JS +cp.v.add = cp.vadd; +cp.v.clamp = cp.vclamp; +cp.v.cross = cp.vcross; +cp.v.dist = cp.vdist; +cp.v.distsq = cp.vdistsq; +cp.v.dot = cp.vdot; +cp.v.eql = cp.veql; +cp.v.forangle = cp.vforangle; +cp.v.len = cp.vlength; +cp.v.lengthsq = cp.vlengthsq; +cp.v.lerp = cp.vlerp; +cp.v.lerpconst = cp.vlerpconst; +cp.v.mult = cp.vmult; +cp.v.near = cp.vnear; +cp.v.neg = cp.vneg; +cp.v.normalize = cp.vnormalize; +cp.v.normalize_safe = cp.vnormalize_safe; +cp.v.perp = cp.vperp; +cp.v.project = cp.vproject; +cp.v.rotate = cp.vrotate; +cp.v.rperp = cp.vrperp; +cp.v.slerp = cp.vslerp; +cp.v.slerpconst = cp.vslerpconst; +cp.v.sub = cp.vsub; +cp.v.toangle = cp.vtoangle; +cp.v.unrotate = cp.vunrotate; + + + +/// Initialize an offset box shaped polygon shape. +cp.BoxShape2 = function(body, box) +{ + var verts = [ + box.l, box.b, + box.l, box.t, + box.r, box.t, + box.r, box.b + ]; + + return new cp.PolyShape(body, verts, cp.vzero); +}; + +/// Initialize a box shaped polygon shape. +cp.BoxShape = function(body, width, height) +{ + var hw = width/2; + var hh = height/2; + + return cp.BoxShape2(body, new cp.BB(-hw, -hh, hw, hh)); +}; + + +/// Initialize an static body +cp.BodyStatic = function() +{ + return new cp.Body(Infinity, Infinity); +}; + + +// "Bounding Box" compatibility with Chipmunk-JS +cp.BB = function(l, b, r, t) +{ + return {l:l, b:b, r:r, t:t}; +}; + +// helper function to create a BB +cp.bb = function(l, b, r, t) { + return new cp.BB(l, b, r, t); +}; + + +// +// Some properties +// +// "handle" needed in some cases +Object.defineProperties(cp.Base.prototype, + { + "handle" : { + get : function(){ + return this.getHandle(); + }, + enumerable : true, + configurable : true + } + }); + +// Properties, for Chipmunk-JS compatibility +// Space properties +Object.defineProperties(cp.Space.prototype, + { + "gravity" : { + get : function(){ + return this.getGravity(); + }, + set : function(newValue){ + this.setGravity(newValue); + }, + enumerable : true, + configurable : true + }, + "iterations" : { + get : function(){ + return this.getIterations(); + }, + set : function(newValue){ + this.setIterations(newValue); + }, + enumerable : true, + configurable : true + }, + "damping" : { + get : function(){ + return this.getDamping(); + }, + set : function(newValue){ + this.setDamping(newValue); + }, + enumerable : true, + configurable : true + }, + "staticBody" : { + get : function(){ + return this.getStaticBody(); + }, + enumerable : true, + configurable : true + }, + "idleSpeedThreshold" : { + get : function(){ + return this.getIdleSpeedThreshold(); + }, + set : function(newValue){ + this.setIdleSpeedThreshold(newValue); + }, + enumerable : true, + configurable : true + }, + "sleepTimeThreshold": { + get : function(){ + return this.getSleepTimeThreshold(); + }, + set : function(newValue){ + this.setSleepTimeThreshold(newValue); + }, + enumerable : true, + configurable : true + }, + "collisionSlop": { + get : function(){ + return this.getCollisionSlop(); + }, + set : function(newValue){ + this.setCollisionSlop(newValue); + }, + enumerable : true, + configurable : true + }, + "collisionBias": { + get : function(){ + return this.getCollisionBias(); + }, + set : function(newValue){ + this.setCollisionBias(newValue); + }, + enumerable : true, + configurable : true + }, + "collisionPersistence": { + get : function(){ + return this.getCollisionPersistence(); + }, + set : function(newValue){ + this.setCollisionPersistence(newValue); + }, + enumerable : true, + configurable : true + }, + "enableContactGraph": { + get : function(){ + return this.getEnableContactGraph(); + }, + set : function(newValue){ + this.setEnableContactGraph(newValue); + }, + enumerable : true, + configurable : true + } + }); + +// Body properties +Object.defineProperties(cp.Body.prototype, + { + "a" : { + get : function(){ + return this.getAngle(); + }, + set : function(newValue){ + this.setAngle(newValue); + }, + enumerable : true, + configurable : true + }, + "w" : { + get : function(){ + return this.getAngVel(); + }, + set : function(newValue){ + this.setAngVel(newValue); + }, + enumerable : true, + configurable : true + }, + "p" : { + get : function(){ + return this.getPos(); + }, + set : function(newValue){ + this.setPos(newValue); + }, + enumerable : true, + configurable : true + }, + "v" : { + get : function(){ + return this.getVel(); + }, + set : function(newValue){ + this.setVel(newValue); + }, + enumerable : true, + configurable : true + }, + "i" : { + get : function(){ + return this.getMoment(); + }, + set : function(newValue){ + this.setMoment(newValue); + }, + enumerable : true, + configurable : true + } + + }); diff --git a/samples/MoonWarriors/Resources/js/helper/jsb_constants_cocos2d.js b/samples/MoonWarriors/Resources/js/helper/jsb_constants_cocos2d.js new file mode 100644 index 0000000000..025d19453b --- /dev/null +++ b/samples/MoonWarriors/Resources/js/helper/jsb_constants_cocos2d.js @@ -0,0 +1,460 @@ +// +// cocos2d constants +// +cc.DIRECTOR_PROJECTION_2D = 0; +cc.DIRECTOR_PROJECTION_3D = 1; + +cc.TEXTURE_PIXELFORMAT_RGBA8888 = 0; +cc.TEXTURE_PIXELFORMAT_RGB888 = 1; +cc.TEXTURE_PIXELFORMAT_RGB565 = 2; +cc.TEXTURE_PIXELFORMAT_A8 = 3; +cc.TEXTURE_PIXELFORMAT_I8 = 4; +cc.TEXTURE_PIXELFORMAT_AI88 = 5; +cc.TEXTURE_PIXELFORMAT_RGBA4444 = 6; +cc.TEXTURE_PIXELFORMAT_RGB5A1 = 7; +cc.TEXTURE_PIXELFORMAT_PVRTC4 = 8; +cc.TEXTURE_PIXELFORMAT_PVRTC4 = 9; +cc.TEXTURE_PIXELFORMAT_DEFAULT = cc.TEXTURE_PIXELFORMAT_RGBA8888; + +cc.TEXT_ALIGNMENT_LEFT = 0; +cc.TEXT_ALIGNMENT_CENTER = 1; +cc.TEXT_ALIGNMENT_RIGHT = 2; + +cc.VERTICAL_TEXT_ALIGNMENT_TOP = 0; +cc.VERTICAL_TEXT_ALIGNMENT_CENTER = 1; +cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM = 2; + +cc.IMAGE_FORMAT_JPEG = 0; +cc.IMAGE_FORMAT_PNG = 0; + +cc.PROGRESS_TIMER_TYPE_RADIAL = 0; +cc.PROGRESS_TIMER_TYPE_BAR = 1; + +cc.PARTICLE_TYPE_FREE = 0; +cc.PARTICLE_TYPE_RELATIVE = 1; +cc.PARTICLE_TYPE_GROUPED = 2; +cc.PARTICLE_DURATION_INFINITY = -1; +cc.PARTICLE_MODE_GRAVITY = 0; +cc.PARTICLE_MODE_RADIUS = 1; +cc.PARTICLE_START_SIZE_EQUAL_TO_END_SIZE = -1; +cc.PARTICLE_START_RADIUS_EQUAL_TO_END_RADIUS = -1; + +cc.TOUCH_ALL_AT_ONCE = 0; +cc.TOUCH_ONE_BY_ONE = 1; + +cc.TMX_TILE_HORIZONTAL_FLAG = 0x80000000; +cc.TMX_TILE_VERTICAL_FLAG = 0x40000000; +cc.TMX_TILE_DIAGONAL_FLAG = 0x20000000; + +cc.TRANSITION_ORIENTATION_LEFT_OVER = 0; +cc.TRANSITION_ORIENTATION_RIGHT_OVER = 1; +cc.TRANSITION_ORIENTATION_UP_OVER = 0; +cc.TRANSITION_ORIENTATION_DOWN_OVER = 1; + +cc.RED = {r:255, g:0, b:0}; +cc.GREEN = {r:0, g:255, b:0}; +cc.BLUE = {r:0, g:0, b:255}; +cc.BLACK = {r:0, g:0, b:0}; +cc.WHITE = {r:255, g:255, b:255}; + +cc.POINT_ZERO = {x:0, y:0}; + +// XXX: This definition is different than cocos2d-html5 +cc.REPEAT_FOREVER = -1; +// reusable objects +cc._reuse_p = [ + {x:0, y:0}, + {x:0, y:0}, + {x:0, y:0}, + {x:0, y:0} +]; +cc._reuse_p_index = 0; +cc._reuse_size = {width:0, height:0}; +cc._reuse_rect = {x:0, y:0, width:0, height:0}; +cc._reuse_color3b = {r:255, g:255, b:255 }; +cc._reuse_color4b = {r:255, g:255, b:255, a:255 }; +cc._reuse_grid = {x:0, y:0}; + +// +// Color 3B +// +cc.c3b = function (r, g, b) { + return {r:r, g:g, b:b }; +}; +cc._c3b = function (r, g, b) { + cc._reuse_color3b.r = r; + cc._reuse_color3b.g = g; + cc._reuse_color3b.b = b; + return cc._reuse_color3b; +}; +// compatibility +cc.c3 = cc.c3b; +cc._c3 = cc._c3b; + +// +// Color 4B +// +cc.c4b = function (r, g, b, a) { + return {r:r, g:g, b:b, a:a }; +}; +cc._c4b = function (r, g, b, a) { + cc._reuse_color4b.r = r; + cc._reuse_color4b.g = g; + cc._reuse_color4b.b = b; + cc._reuse_color4b.a = a; + return cc._reuse_color4b; +}; +// compatibility +cc.c4 = cc.c4b; +cc._c4 = cc._c4b; + + +// +// Color 4F +// +cc.c4f = function (r, g, b, a) { + return {r:r, g:g, b:b, a:a }; +}; + +// +// Point +// +cc.p = function (x, y) { + return {x:x, y:y}; +}; +cc._p = function (x, y) { + if (cc._reuse_p_index == cc._reuse_p.length) + cc._reuse_p_index = 0; + + var p = cc._reuse_p[ cc._reuse_p_index]; + cc._reuse_p_index++; + p.x = x; + p.y = y; + return p; +}; + +cc.pointEqualToPoint = function (point1, point2) { + return ((point1.x == point2.x) && (point1.y == point2.y)); +}; + +// +// Grid +// +cc.g = function (x, y) { + return {x:x, y:y}; +}; +cc._g = function (x, y) { + cc._reuse_grid.x = x; + cc._reuse_grid.y = y; + return cc._reuse_grid; +}; + +// +// Size +// +cc.size = function (w, h) { + return {width:w, height:h}; +}; +cc._size = function (w, h) { + cc._reuse_size.width = w; + cc._reuse_size.height = h; + return cc._reuse_size; +}; +cc.sizeEqualToSize = function (size1, size2) { + return ((size1.width == size2.width) && (size1.height == size2.height)); +}; + +// +// Rect +// +cc.rect = function (x, y, w, h) { + return {x:x, y:y, width:w, height:h}; +}; + +cc._rect = function (x, y, w, h) { + cc._reuse_rect.x = x; + cc._reuse_rect.y = y; + cc._reuse_rect.width = w; + cc._reuse_rect.height = h; + return cc._reuse_rect; +}; +cc.rectEqualToRect = function (rect1, rect2) { + return ( rect1.x == rect2.x && rect1.y == rect2.y && rect1.width == rect2.width && rect1.height == rect2.height); +}; + +cc.rectContainsRect = function (rect1, rect2) { + if ((rect1.x >= rect2.x) || (rect1.y >= rect2.y) || + ( rect1.x + rect1.width <= rect2.x + rect2.width) || + ( rect1.y + rect1.height <= rect2.y + rect2.height)) + return false; + return true; +}; + +cc.rectGetMaxX = function (rect) { + return (rect.x + rect.width); +}; + +cc.rectGetMidX = function (rect) { + return (rect.x + rect.width / 2.0); +}; + +cc.rectGetMinX = function (rect) { + return rect.x; +}; + +cc.rectGetMaxY = function (rect) { + return(rect.y + rect.height); +}; + +cc.rectGetMidY = function (rect) { + return rect.y + rect.height / 2.0; +}; + +cc.rectGetMinY = function (rect) { + return rect.y; +}; + +cc.rectContainsPoint = function (rect, point) { + var ret = false; + if (point.x >= rect.x && point.x <= rect.x + rect.width && + point.y >= rect.y && point.y <= rect.y + rect.height) { + ret = true; + } + return ret; +}; + + +// XXX Should be done in native +cc.rectIntersectsRect = function (rectA, rectB) { + var bool = !( rectA.x > rectB.x + rectB.width || + rectA.x + rectA.width < rectB.x || + rectA.y > rectB.y + rectB.height || + rectA.y + rectA.height < rectB.y ); + + return bool; +}; + +cc.rectUnion = function (rectA, rectB) { + var rect = cc.rect(0, 0, 0, 0); + rect.x = Math.min(rectA.x, rectB.x); + rect.y = Math.min(rectA.y, rectB.y); + rect.width = Math.max(rectA.x + rectA.width, rectB.x + rectB.width) - rect.x; + rect.height = Math.max(rectA.y + rectA.height, rectB.y + rectB.height) - rect.y; + return rect; +}; + +cc.rectIntersection = function (rectA, rectB) { + var intersection = cc.rect( + Math.max(rectA.x, rectB.x), + Math.max(rectA.y, rectB.y), + 0, 0); + + intersection.width = Math.min(rectA.x + rectA.width, rectB.x + rectB.width) - intersection.x; + intersection.height = Math.min(rectA.y + rectA.height, rectB.y + rectB.height) - intersection.y; + return intersection; +}; + +// +// Array: for cocos2d-html5 compatibility +// +cc.ArrayRemoveObject = function (arr, delObj) { + for (var i = 0; i < arr.length; i++) { + if (arr[i] == delObj) { + arr.splice(i, 1); + } + } +}; + +// +// Helpers +// +cc.dump = function (obj) { + for (var i in obj) + cc.log(i + " = " + obj[i]); +}; + +// dump config info, but only in debug mode +cc.dumpConfig = function () { + if (cc.config.debug) + cc.dump(cc.config); +}; + +// +// Bindings Overrides +// +// MenuItemToggle +cc.MenuItemToggle.create = function( /* var args */) { + + var n = arguments.length; + + if (typeof arguments[n-2] === 'function' || typeof arguments[n-1] === 'function') { + var args = Array.prototype.slice.call(arguments); + var obj = null; + if( typeof arguments[n-2] === 'function' ) + obj = args.pop(); + + var func = args.pop(); + + // create it with arguments, + var item = cc.MenuItemToggle._create.apply(this, args); + + // then set the callback + if( obj !== null ) + item.setCallback(func, obj); + else + item.setCallback(func); + return item; + } else { + return cc.MenuItemToggle._create.apply(this, arguments); + } +}; + +// LabelAtlas +cc.LabelAtlas.create = function( a,b,c,d,e ) { + + var n = arguments.length; + + if ( n == 5) { + return cc.LabelAtlas._create(a,b,c,d,e.charCodeAt(0)); + } else { + return cc.LabelAtlas._create.apply(this, arguments); + } +}; + +/** + * Associates a base class with a native superclass + * @function + * @param {object} jsobj subclass + * @param {object} klass superclass + */ +cc.associateWithNative = function (jsobj, superclass_or_instance) { + + try { + // Used when subclassing using the "extend" method + var native = new superclass_or_instance(); + __associateObjWithNative(jsobj, native); + } catch (err) { + // Used when subclassing using the goog.inherits method + __associateObjWithNative(jsobj, superclass_or_instance); + } +}; + +// +// JSB supports 2 official ways to create subclasses +// +// 1) Google "subclasses" borrowed from closure library +// This is the recommended way to do it +// +cc.inherits = function (childCtor, parentCtor) { + /** @constructor */ + function tempCtor() {}; + tempCtor.prototype = parentCtor.prototype; + childCtor.superClass_ = parentCtor.prototype; + childCtor.prototype = new tempCtor(); + childCtor.prototype.constructor = childCtor; + + // Copy "static" method, but doesn't generate subclasses. +// for( var i in parentCtor ) { +// childCtor[ i ] = parentCtor[ i ]; +// } +}; + +cc.base = function (me, opt_methodName, var_args) { + var caller = arguments.callee.caller; + if (caller.superClass_) { + // This is a constructor. Call the superclass constructor. + ret = caller.superClass_.constructor.apply(me, Array.prototype.slice.call(arguments, 1)); + return ret; + } + + var args = Array.prototype.slice.call(arguments, 2); + var foundCaller = false; + for (var ctor = me.constructor; + ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) { + if (ctor.prototype[opt_methodName] === caller) { + foundCaller = true; + } else if (foundCaller) { + return ctor.prototype[opt_methodName].apply(me, args); + } + } + + // If we did not find the caller in the prototype chain, + // then one of two things happened: + // 1) The caller is an instance method. + // 2) This method was not called by the right caller. + if (me[opt_methodName] === caller) { + return me.constructor.prototype[opt_methodName].apply(me, args); + } else { + throw Error( + 'cc.base called from a method of one name ' + + 'to a method of a different name'); + } +}; + + +// +// 2) Using "extend" subclassing +// Simple JavaScript Inheritance By John Resig http://ejohn.org/ +// +cc.Class = function () {}; +cc.Class.extend = function (prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function (name, fn) { + return function () { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if (!initializing && this.ctor) + this.ctor.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; +}; + +cc.Node.prototype.ctor = function () {}; +cc.Node.extend = cc.Class.extend; +cc.Layer.extend = cc.Class.extend; +cc.LayerGradient.extend = cc.Class.extend; +cc.LayerColor.extend = cc.Class.extend; +cc.Sprite.extend = cc.Class.extend; +cc.MenuItemFont.extend = cc.Class.extend; +cc.Scene.extend = cc.Class.extend; diff --git a/samples/MoonWarriors/Resources/js/helper/jsb_constants_cocosbuilder.js b/samples/MoonWarriors/Resources/js/helper/jsb_constants_cocosbuilder.js new file mode 100644 index 0000000000..306c5e7934 --- /dev/null +++ b/samples/MoonWarriors/Resources/js/helper/jsb_constants_cocosbuilder.js @@ -0,0 +1,118 @@ +// +// CocosBuilder definitions +// + +cc.Reader = {}; + +var _ccbGlobalContext = this; + +cc.Reader.load = function(file, owner, parentSize) +{ + // Load the node graph using the correct function + var reader = cc._Reader.create(); + var node; + + if (owner && parentSize) + { + node = reader.load(file, owner, parentSize); + } + else if (owner) + { + node = reader.load(file,owner); + } + else + { + node = reader.load(file); + } + + // Assign owner callbacks & member variables + if (owner) + { + // Callbacks + var ownerCallbackNames = reader.getOwnerCallbackNames(); + var ownerCallbackNodes = reader.getOwnerCallbackNodes(); + + for (var i = 0; i < ownerCallbackNames.length; i++) + { + var callbackName = ownerCallbackNames[i]; + var callbackNode = ownerCallbackNodes[i]; + + callbackNode.setCallback(owner[callbackName], owner); + } + + // Variables + var ownerOutletNames = reader.getOwnerOutletNames(); + var ownerOutletNodes = reader.getOwnerOutletNodes(); + + for (var i = 0; i < ownerOutletNames.length; i++) + { + var outletName = ownerOutletNames[i]; + var outletNode = ownerOutletNodes[i]; + + owner[outletName] = outletNode; + } + } + + var nodesWithAnimationManagers = reader.getNodesWithAnimationManagers(); + var animationManagersForNodes = reader.getAnimationManagersForNodes(); + + // Attach animation managers to nodes and assign root node callbacks and member variables + for (var i = 0; i < nodesWithAnimationManagers.length; i++) + { + var innerNode = nodesWithAnimationManagers[i]; + var animationManager = animationManagersForNodes[i]; + + innerNode.animationManager = animationManager; + + var documentControllerName = animationManager.getDocumentControllerName(); + if (!documentControllerName) continue; + + // Create a document controller + var controller = new _ccbGlobalContext[documentControllerName](); + controller.controllerName = documentControllerName; + + innerNode.controller = controller; + controller.rootNode = innerNode; + + // Callbacks + var documentCallbackNames = animationManager.getDocumentCallbackNames(); + var documentCallbackNodes = animationManager.getDocumentCallbackNodes(); + + for (var j = 0; j < documentCallbackNames.length; j++) + { + var callbackName = documentCallbackNames[j]; + var callbackNode = documentCallbackNodes[j]; + + callbackNode.setCallback(controller[callbackName], controller); + } + + + // Variables + var documentOutletNames = animationManager.getDocumentOutletNames(); + var documentOutletNodes = animationManager.getDocumentOutletNodes(); + + for (var j = 0; j < documentOutletNames.length; j++) + { + var outletName = documentOutletNames[j]; + var outletNode = documentOutletNodes[j]; + + controller[outletName] = outletNode; + } + + if (typeof(controller.onDidLoadFromCCB) == "function") + { + controller.onDidLoadFromCCB(); + } + } + + return node; +} + +cc.Reader.loadAsScene = function(file, owner, parentSize) +{ + var node = cc.Reader.load(file, owner, parentSize); + var scene = cc.Scene.create(); + scene.addChild( node ); + + return scene; +} diff --git a/scripting/javascript/bindings/cocos2d_specifics.cpp b/scripting/javascript/bindings/cocos2d_specifics.cpp index 441d9d37bb..b9799763cc 100644 --- a/scripting/javascript/bindings/cocos2d_specifics.cpp +++ b/scripting/javascript/bindings/cocos2d_specifics.cpp @@ -244,19 +244,43 @@ JSBool js_cocos2dx_CCMenuItemSprite_create(JSContext *cx, uint32_t argc, jsval * TEST_NATIVE_OBJECT(cx, arg1); int last = 2; + JSBool thirdArgIsCallback = JS_FALSE; + + jsval jsCallback = JSVAL_VOID; + jsval jsThis = JSVAL_VOID; + cocos2d::CCNode* arg2 = NULL; - if (argc == 5 || argc == 3) { + if (argc >= 3) { tmpObj = JSVAL_TO_OBJECT(argv[2]); - JS_GET_NATIVE_PROXY(proxy, tmpObj); - arg2 = (cocos2d::CCNode*)(proxy ? proxy->ptr : NULL); - TEST_NATIVE_OBJECT(cx, arg2); - last = 3; + thirdArgIsCallback = JS_ObjectIsFunction(cx, tmpObj); + if (!thirdArgIsCallback) { + JS_GET_NATIVE_PROXY(proxy, tmpObj); + arg2 = (cocos2d::CCNode*)(proxy ? proxy->ptr : NULL); + TEST_NATIVE_OBJECT(cx, arg2); + last = 3; + } } cocos2d::CCMenuItemSprite* ret = cocos2d::CCMenuItemSprite::create(arg0, arg1, arg2); + if (argc >= 3) { + if (thirdArgIsCallback) { + //cc.MenuItemSprite.create( normalSprite, selectedSprite, callback_fn, [this] ) + jsCallback = argv[last++]; + if (argc == 4) { + jsThis = argv[last]; + } + } + else { + //cc.MenuItemSprite.create( normalSprite, selectedSprite, disabledSprite, callback_fn, [this] ) + if (argc >= 4) { + jsCallback = argv[last++]; + if (argc == 5) { + jsThis = argv[last]; + } + } + } + } - jsval callback = argv[last++]; - jsval thisObj = argv[last]; - JSObject *obj = bind_menu_item(cx, ret, callback, thisObj); + JSObject *obj = bind_menu_item(cx, ret, jsCallback, jsThis); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return JS_TRUE; } @@ -273,22 +297,42 @@ JSBool js_cocos2dx_CCMenuItemImage_create(JSContext *cx, uint32_t argc, jsval *v const char *arg0; do { JSString *tmp = JS_ValueToString(cx, argv[0]); arg0 = JS_EncodeString(cx, tmp); } while (0); const char *arg1; do { JSString *tmp = JS_ValueToString(cx, argv[1]); arg1 = JS_EncodeString(cx, tmp); } while (0); const char *arg2 = NULL; + + JSBool thirdArgIsString = JS_TRUE; + + jsval jsCallback = JSVAL_VOID; + jsval jsThis = JSVAL_VOID; + int last = 2; - if (JSVAL_IS_STRING(argv[2])) { - do { JSString *tmp = JS_ValueToString(cx, argv[2]); arg2 = JS_EncodeString(cx, tmp); } while (0); - last = 3; + if (argc >= 3) { + thirdArgIsString = JSVAL_IS_STRING(argv[2]); + if (thirdArgIsString) { + do { JSString *tmp = JS_ValueToString(cx, argv[2]); arg2 = JS_EncodeString(cx, tmp); } while (0); + last = 3; + } } cocos2d::CCMenuItemImage* ret = cocos2d::CCMenuItemImage::create(arg0, arg1, arg2); - jsval thisObj = JSVAL_VOID; - jsval callback = JSVAL_VOID; - if(argc > 3) { - callback = argv[last++]; - thisObj = argv[last]; - } - else if (argc == 3 && last == 2) { - callback = argv[last++]; - } - JSObject *obj = bind_menu_item(cx, ret, callback, thisObj); + + if (argc >= 3) { + if (!thirdArgIsString) { + //cc.MenuItemImage.create( normalImage, selectedImage, callback_fn, [this] ) + jsCallback = argv[last++]; + if (argc == 4) { + jsThis = argv[last]; + } + } + else { + //cc.MenuItemImage.create( normalImage, selectedImage, disabledImage, callback_fn, [this] ) + if (argc >= 4) { + jsCallback = argv[last++]; + if (argc == 5) { + jsThis = argv[last]; + } + } + } + } + + JSObject *obj = bind_menu_item(cx, ret, jsCallback, jsThis); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); return JS_TRUE; } @@ -1238,6 +1282,45 @@ JSBool js_cocos2dx_ccpClamp(JSContext *cx, uint32_t argc, jsval *vp) return JS_FALSE; } +JSBool js_cocos2dx_ccpLengthSQ(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + + if (argc == 1) { + cocos2d::CCPoint arg0; + arg0 = jsval_to_ccpoint(cx, argv[0]); + + float ret = ccpLengthSQ(arg0); + + jsval jsret = DOUBLE_TO_JSVAL(ret); + JS_SET_RVAL(cx, vp, jsret); + return JS_TRUE; + + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return JS_FALSE; +} + +JSBool js_cocos2dx_ccpLength(JSContext *cx, uint32_t argc, jsval *vp) +{ + jsval *argv = JS_ARGV(cx, vp); + + if (argc == 1) { + cocos2d::CCPoint arg0; + arg0 = jsval_to_ccpoint(cx, argv[0]); + + float ret = ccpLength(arg0); + + jsval jsret = DOUBLE_TO_JSVAL(ret); + JS_SET_RVAL(cx, vp, jsret); + return JS_TRUE; + + } + + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + return JS_FALSE; +} JSBool js_cocos2dx_ccpNeg(JSContext *cx, uint32_t argc, jsval *vp) { @@ -1325,7 +1408,7 @@ JSBool js_cocos2dx_ccpMidpoint(JSContext *cx, uint32_t argc, jsval *vp) } - JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); return JS_FALSE; } @@ -1348,7 +1431,7 @@ JSBool js_cocos2dx_ccpDot(JSContext *cx, uint32_t argc, jsval *vp) } - JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); return JS_FALSE; } @@ -1370,7 +1453,7 @@ JSBool js_cocos2dx_ccpCross(JSContext *cx, uint32_t argc, jsval *vp) } - JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); return JS_FALSE; } @@ -1436,7 +1519,7 @@ JSBool js_cocos2dx_ccpProject(JSContext *cx, uint32_t argc, jsval *vp) } - JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); return JS_FALSE; } @@ -1458,7 +1541,7 @@ JSBool js_cocos2dx_ccpRotate(JSContext *cx, uint32_t argc, jsval *vp) } - JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 1); + JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 2); return JS_FALSE; } @@ -1713,8 +1796,8 @@ void register_cocos2dx_js_extensions(JSContext* cx, JSObject* global) JS_DefineFunction(cx, ns, "pRotate", js_cocos2dx_ccpRotate, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, ns, "pNormalize", js_cocos2dx_ccpNormalize, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(cx, ns, "pClamp", js_cocos2dx_ccpClamp, 2, JSPROP_READONLY | JSPROP_PERMANENT); - - + JS_DefineFunction(cx, ns, "pLengthSQ", js_cocos2dx_ccpLengthSQ, 1, JSPROP_READONLY | JSPROP_PERMANENT); + JS_DefineFunction(cx, ns, "pLength", js_cocos2dx_ccpLength, 1, JSPROP_READONLY | JSPROP_PERMANENT); // add constructor for CCSet JSFunction *ccSetConstructor = JS_NewFunction(cx, js_cocos2dx_CCSet_constructor, 0, JSPROP_READONLY | JSPROP_PERMANENT, NULL, "constructor");