十四 手游开发神器 cocos2d-x editor 之串联游戏流程

原创 2014年01月25日 18:10:31

一般游戏都包括几个流程,加载界面,开始界面,选关界面,主界面,暂停界面等等;这节我将这些流程都串联起来;


代码下载:http://share.weiyun.com/c3f24a752d5e6f26ca3e1e97855807f6(snow-flow)


loading界面;


LoadingLayer.ccbx

<?xml version="1.0" encoding="UTF-8"?>

<Document
        jsControlled="true"
        jsController=""
        resolution="default"
        >

    <Resolutions>
        <Resolution centeredOrigin="false" ext="iphone" height="1280" width="720" name="default" scale="1"/>
        <Resolution centeredOrigin="false" ext="iphone" height="720" width="1280" name="default1" scale="1"/>
    </Resolutions>

    <Animations>
        <Animation autoPlay="true"
                   id="0"
                   name="Default Timeline"
                   length="10"
                   chainedId="0"
                   offset="0.0"
                   position="0.0"
                   resolution="30"
                   scale="128">
            <CallbackChannel>
            </CallbackChannel>
            <SoundChannel>
            </SoundChannel>
        </Animation>

    </Animations>

    <Layer
            positionX="0" positionY="0"
            width="100" height="100" sizeType="Percent"
            anchorPointX="0.5" anchorPointY="0.5" ignoreAnchorPoint="true"
            scaleX="1" scaleY="1"
            touchEnabled="true" positionType="LeftBottom" target="Owner">
        <LayerColor positionType="LeftBottom" width="720" height="1280" positionX="0" positionY="0" anchorPointX="0"
                    anchorPointY="0" color="#ffff40b8" target="Doc"/>
        <Sprite positionType="LeftBottom" width="245.0" height="72.0" positionX="381.0" positionY="661.0" anchorPointX="0.5"
                                         anchorPointY="0.5" src="Resources/snow_packer.plist/sa_loading_0001.png"
                                         target="Owner"/>
    </Layer>


</Document>


开始界面;


StartLayer.ccbx

<?xml version="1.0" encoding="UTF-8"?>

<Document
        jsControlled="true"
        jsController="StartLayer"
        resolution="default"
        >

    <Resolutions>
        <Resolution centeredOrigin="false" ext="iphone" height="1280" width="720" name="default" scale="1"/>
        <Resolution centeredOrigin="false" ext="iphone" height="720" width="1280" name="default1" scale="1"/>
    </Resolutions>

    <Animations>
        <Animation autoPlay="true"
                   id="0"
                   name="Default Timeline"
                   length="10"
                   chainedId="0"
                   offset="0.0"
                   position="0.0"
                   resolution="30"
                   scale="128">
            <CallbackChannel>
            </CallbackChannel>
            <SoundChannel>
            </SoundChannel>
        </Animation>

    </Animations>

    <Layer
            positionX="0" positionY="0"
            width="100" height="100" sizeType="Percent"
            anchorPointX="0.5" anchorPointY="0.5" ignoreAnchorPoint="true"
            scaleX="1" scaleY="1"
            touchEnabled="true" positionType="LeftBottom" visible="true">
        <LayerColor positionType="LeftBottom" width="720" height="1280" positionX="0" positionY="0" anchorPointX="0"
                    anchorPointY="0" color="#ff10ff9e"/>
        <Menu positionType="LeftBottom" width="40" height="40" positionX="354.0" positionY="712.0" anchorPointX="0.5"
              anchorPointY="0.5">
            <MenuItem positionType="LeftBottom" width="203" height="129" positionX="0" positionY="0" anchorPointX="0.5"
                      anchorPointY="0.5" onClick="onPlayClicked" normalImage="Resources/snow_packer.plist/m_play.png"
                      target="Doc" selectedImage="Resources/snow_packer.plist/m_play.png"/>
        </Menu>
    </Layer>


</Document>

StartLayer.js

//
// CleanerScoreScene class
//
var StartLayer = function () {
    cc.log("StartLayer")
    this.LoadingLayer = this.LoadingLayer || {};
    this.passTime = 0;
    this.goStart = false;
};

StartLayer.prototype.onDidLoadFromCCB = function () {
//    this.rootNode.onUpdate = function (dt)
//    {
//        this.controller.onUpdate();
//    };
//    this.rootNode.schedule(this.rootNode.onUpdate);

    if (sys.platform == 'browser') {
        this.onEnter();
    }
    else {
        this.rootNode.onEnter = function () {
            this.controller.onEnter();
        };
    }

    this.rootNode.onExit = function () {
        this.controller.onExit();
    };

    this.rootNode.schedule(function (dt) {
        this.controller.onUpdate(dt);
    });
};

StartLayer.prototype.onEnter = function () {
    this.LoadingLayer = cc.BuilderReader.loadAsNodeFrom("", "LoadingLayer", this);
    this.LoadingLayer.setPosition(cc.p(0, 0));
    this.LoadingLayer.setZOrder(200);
    this.rootNode.addChild(this.LoadingLayer);
    //  cc.Director.getInstance().pause();
    /*this.LoadingLayer.scheduleOnce(this.removeLoading, 1);*/
    this.goStart = true;
    this.startTime = this.passTime;

}

StartLayer.prototype.removeLoading = function () {
    // if (this.LoadingLayer) {
    cc.log("removeLoading");
    // cc.Director.getInstance().resume();
    this.LoadingLayer.removeFromParent();
}

StartLayer.prototype.onUpdate = function (dt) {
    this.passTime += dt;
    if (this.passTime - this.startTime > 3 && this.goStart) {
        this.removeLoading();
        this.goStart = false;
    }
}

StartLayer.prototype.onPlayClicked = function () {
    cc.BuilderReader.runScene("", "GameSelectLayer");
}

StartLayer.prototype.onExit = function () {

}


选关界面


GameSelectLayer.ccbx

<?xml version="1.0" encoding="UTF-8"?>

<Document
        jsControlled="true"
        jsController="GameSelectLayer"
        resolution="default"
        >

  <Resolutions>
    <Resolution centeredOrigin="false" ext="iphone" height="1280" width="720" name="default" scale="1"/>
    <Resolution centeredOrigin="false" ext="iphone" height="720" width="1280" name="default1" scale="1"/>
  </Resolutions>

  <Animations>
    <Animation autoPlay="true"
               id="0"
               name="Default Timeline"
               length="10"
               chainedId="0"
               offset="0.0"
               position="0.0"
               resolution="30"
               scale="128">
      <CallbackChannel>
      </CallbackChannel>
      <SoundChannel>
      </SoundChannel>
    </Animation>

  </Animations>

  <Layer
          positionX="0" positionY="0"
          width="100" height="100" sizeType="Percent"
          anchorPointX="0.5" anchorPointY="0.5" ignoreAnchorPoint="true"
          scaleX="1" scaleY="1"
          touchEnabled="true" positionType="LeftBottom">

    <LayerColor positionType="LeftBottom" width="720" height="1280" positionX="0" positionY="0" anchorPointX="0"
                  anchorPointY="0" color="#ff20b4ff"/>
      <Sprite name="bg_g" var="b1" target="Doc" positionX="360" positionY="641"
            positionType="LeftBottom" anchorPointX="0.5" anchorPointY="0.5"
            scaleX="1" scaleY="1" scaleType="Absolute" ignoreAnchorPoint="false"
            src="Resources/s_bg_grade.png" visible="false" color="#ffffffff"/>
    <Sprite positionType="LeftBottom" width="587.0" height="834" positionX="361.0" positionY="689.0" anchorPointX="0.5"
            anchorPointY="0.5" src="Resources/s_bg_grade.png">
        <Node positionType="LeftBottom" width="40" height="100" positionX="42.0" positionY="42.0" anchorPointX="0"
            anchorPointY="0" target="Doc" var="listTop">
      <ScrollView name="levelScrollPanel"
                  var="levelScrollPanel" target="Doc" positionX="0" positionY="100"
                  positionType="LeftBottom" width="510" height="500"
                  sizeType="Absolute" anchorPointX="0" anchorPointY="0"
                  scaleX="1" scaleY="1"
                  clipsToBounds="true"
                  direction="Horizontal"
                  bounces="true"
                  ignoreAnchorPoint="true" visible="true" touchEnabled="true" mouseEnabled="true">
      </ScrollView></Node>
        <Node positionType="LeftBottom" width="40" height="40" positionX="268.0" positionY="73.0" anchorPointX="0.5"
              anchorPointY="0.5" var="dotNode" target="Doc"/>

    </Sprite>
  </Layer>


</Document>

GameSelectLayer.js

GAME_LEVEL = 0;
var GameSelectLayer = function () {
    cc.log("GameSelectLayer");
    this.levelScrollPanel = this.levelScrollPanel || {};
    this.pageIndex = 0;
    this.pageMax = 4;
    this.dotNode = this.dotNode || {};
    this.start = false;

};

GameSelectLayer.prototype.onDidLoadFromCCB = function () {
    if (sys.platform == 'browser') {
        this.onEnter();
    }
    else {
        this.rootNode.onEnter = function () {
            this.controller.onEnter();
        };
    }

    this.rootNode.onExit = function () {
        this.controller.onExit();
    };


    this.rootNode.onTouchesBegan = function (touches, event) {
        this.controller.onTouchesBegan(touches, event);
        return true;
    };

    this.rootNode.onTouchesMoved = function (touches, event) {
        this.controller.onTouchesMoved(touches, event);
        return true;
    };
    this.rootNode.onTouchesEnded = function (touches, event) {
        this.controller.onTouchesEnded(touches, event);
        return true;
    };
    this.rootNode.setTouchEnabled(true);
};

GameSelectLayer.prototype.onEnter = function () {
    this.maxColumns = 3;
    this.columnSize = 177;
    this.maxRows = 5;
    this.rowSize = 104;
    cc.log("GameSelectLayer");

    this.itemDatas = [];
    var itemName = "";
    var levelPan = cc.Layer.create();
    var currentLevel = sys.localStorage.getItem("pb_level");
    if (currentLevel == null) {
        currentLevel = 0;
    }

    sys.localStorage.setItem("pb_level_score_1", "S");
    currentLevel = 3;

    for (var i = 0; i < 50; i++) {
        var xIndex = Math.floor(i % 3) + Math.floor(i / 15) * 3;
        var yIndex = Math.floor(i / 3 % 5);
        var levelScore = "A"
        if (i < currentLevel) {
            levelScore = sys.localStorage.getItem("pb_level_score_" + i);
            if (levelScore == null || levelScore == '') {
                levelScore = "A";
            }
            if ("S" == levelScore) {
                itemName = "GameSelectItemScoreS";
            }
            else {
                itemName = "GameSelectItemScore";
            }
        }
        else if (i == currentLevel) {
            itemName = "GameSelectItemLevel";
        }
        else {
            itemName = "GameSelectItemLocked";
        }
        var itemData = {
            xIndex: xIndex,
            yIndex: yIndex,
            index: i,
            type: itemName,
            onItemAction: function () {
                cc.log("onItemAction");
                var action = cc.ScaleBy.create(0.5, 0.8);
                this.rootNode.runAction(cc.Sequence.create(
                    action, action.reverse(), cc.DelayTime.create(2)
                    //  cc.CallFunc.create(this.onItemClicked())
                ));
            },
            onItemClicked: function () {
                cc.log("onItemClicked");
                GAME_LEVEL = (this.index + 1);
                require("MainLayer.js");
                cc.BuilderReader.runScene("", "MainLayer");
            },
            onLockOpened: function () {
            }
        };
        var item = cc.BuilderReader.loadAsNodeFrom("", "GameSelectItemSprite", itemData);
        if (item == null) {
            continue;
        }
        item.setPosition(cc.p(this.columnSize * xIndex, this.rowSize * (4 - yIndex)));
        item.setZOrder(11);
        itemData.rootNode = item;
        itemData.controller = this;
        this.itemDatas.push(itemData);
        itemData.levelNum.setString("" + (i + 1));
        levelPan.addChild(item);
    }
    levelPan.setContentSize(cc.size(this.columnSize * 12, this.rowSize * 5));
    this.levelScrollPanel.setTouchEnabled(false);
    this.levelScrollPanel.setBounceable(true);
    this.levelScrollPanel.setContainer(levelPan);
    this.levelScrollPanel.setTouchPriority(-99999);

    this.pageDots(0);
}

GameSelectLayer.prototype.onUpdate = function () {

}

GameSelectLayer.prototype.onExit = function () {

}

GameSelectLayer.prototype.onTouchesBegan = function (touches, event) {
    cc.log("onTouchesBegan");
    this.beganPosition = touches[0].getLocation();
}

GameSelectLayer.prototype.onTouchesMoved = function (touches, event) {
    this.movePosition = touches[0].getLocation();
}

GameSelectLayer.prototype.onTouchesEnded = function (touches, event) {
    cc.log("onTouchesEnded");
    var loc = touches[0].getLocation();
    var distanceX = this.beganPosition.x - loc.x;

    var x = this.levelScrollPanel.getContentOffset().x;
    var y = this.levelScrollPanel.getContentOffset().y;
    this.levelScrollPanel.unscheduleAllCallbacks();

    if (distanceX > 50) {
        if (this.pageIndex < 4) {
            this.pageIndex += 1;
        }
        this.pageDots(this.pageIndex);
    }
    else if (distanceX < -50) {
        if (this.pageIndex > 0) {
            this.pageIndex -= 1;
        }
        this.pageDots(this.pageIndex);
    }
    else {
        this.onItemClicked(loc);
    }
    this.levelScrollPanel.setContentOffsetInDuration(cc.p(-this.columnSize * 3 * this.pageIndex, y), 0.5);
}

GameSelectLayer.prototype.onItemClicked = function (location) {
    var x = location.x;
    var y = location.y;

    if (!isInScroll(location)) {
        cc.log("out");
        return;
    }

    var scrollPanelRect = this.levelScrollPanel.getBoundingBox();
    var xIndex = Math.floor((x - 110) / this.columnSize) + this.pageIndex * 3;
    var yIndex = 4 - Math.floor((y - 385) / this.rowSize);
    cc.log("scrollX==" + scrollPanelRect.x + ",scrollY==" + scrollPanelRect.y);
    cc.log("xIndex==" + xIndex + ",yIndex==" + yIndex);

    for (var i = 0; i < this.itemDatas.length; i++) {
        if (this.itemDatas[i].xIndex == xIndex && this.itemDatas[i].yIndex == yIndex) {
            cc.log("click i=" + i);
            this.itemDatas[i].onItemClicked();
            break;
        }
    }
}

GameSelectLayer.prototype.pageDots = function (position) {
    this.dotNode.removeAllChildren();
    for (var i = 0; i < 4; i++) {
        var dots = ["s_point.png", "s_point_s.png"];
        var type = 0;
        if (position == i) {
            type = 1;
        }
        var dotSprite = cc.Sprite.createWithSpriteFrameName(dots[type]);
        dotSprite.setAnchorPoint(cc.p(0, 1));
        dotSprite.setPosition(cc.p(30 * i, 60));
        dotSprite.setZOrder(100);
        this.dotNode.addChild(dotSprite);
    }
}

function isInScroll(location) {
    var x = location.x;
    var y = location.y;
    if (x > 110 && x < (110 + 510) && y > 385 && y < (385 + 500)) {
        return true;
    }
    return false
}

GameSelectItemSprite.ccbx

<?xml version="1.0" encoding="UTF-8"?>

<Document
        jsControlled="true"
        jsController=""
        resolution="default"
        >

  <Resolutions>
    <Resolution centeredOrigin="false" ext="iphone" height="1280" width="720" name="default" scale="1"/>
    <Resolution centeredOrigin="false" ext="iphone" height="720" width="1280" name="default1" scale="1"/>
  </Resolutions>

  <Animations>
    <Animation autoPlay="true"
               id="0"
               name="Default Timeline"
               length="10"
               chainedId="0"
               offset="0.0"
               position="0.0"
               resolution="30"
               scale="128">
      <CallbackChannel>
      </CallbackChannel>
      <SoundChannel>
      </SoundChannel>
    </Animation>

  </Animations>
  <Sprite
          positionX="0" positionY="0"
          sizeType="Absolute"
          anchorPointX="0.5" anchorPointY="0.5" ignoreAnchorPoint="true"
          scaleX="1.0" scaleY="1.0"
          positionType="LeftBottom" src="Resources/snow_packer.plist/s_bun_red_normal.png" target="Owner" var="bgSprite" width="156" height="83"
          color="#ff15ffa0">
    <LayerColor positionType="LeftBottom" width="156" height="83" positionX="0" positionY="0" anchorPointX="0"
                  anchorPointY="0" color="#ff0cffa2" visible="true"/>
      <Sprite positionType="LeftBottom" width="77.0" height="77.0" positionX="113.0" positionY="40.0" anchorPointX="0.5"
                                         anchorPointY="0.5" src="Resources/snow_packer.plist/m_star_s.png"
                                         scaleX="0.6" scaleY="0.6"/>
    <LabelBMFont positionType="LeftBottom" width="40" height="40" positionX="39.0" positionY="56.0" anchorPointX="0.5"
                 anchorPointY="0.5" text="2" src="Resources/fonts/s_number_gold.fnt" var="levelNum" target="Owner" name="levelNum"
                 scaleX="1.5" scaleY="1.5"/>
      </Sprite>


</Document>



主游戏场景;


MainLayer.ccbx

<?xml version="1.0" encoding="UTF-8"?>

<Document
        jsControlled="true"
        jsController="MainLayer"
        resolution="default"
        >

    <Resolutions>
        <Resolution centeredOrigin="false" ext="iphone" height="1280" width="720" name="default" scale="1"/>
        <Resolution centeredOrigin="false" ext="iphone" height="720" width="1280" name="default1" scale="1"/>
    </Resolutions>

    <Animations>
        <Animation autoPlay="true"
                   id="0"
                   name="Default Timeline"
                   length="10"
                   chainedId="0"
                   offset="0.0"
                   position="0.0"
                   resolution="30"
                   scale="128">
            <CallbackChannel>
            </CallbackChannel>
            <SoundChannel>
            </SoundChannel>
        </Animation>

    </Animations>
    <Layer
            positionX="0" positionY="0.0"
            sizeType="Percent"
            width="100" height="100"
            anchorPointX="0.5" anchorPointY="0.5" ignoreAnchorPoint="true"
            scaleX="1" scaleY="1"
            >

        <Sprite positionType="LeftBottom" width="720" height="1280" positionX="0" positionY="0"
                anchorPointX="0"
                anchorPointY="0" src="Resources/m_bg_main.jpg">
        <Sprite positionType="LeftBottom" width="182.0" height="238.0" positionX="117.0" positionY="1133.0" anchorPointX="0.5"
                                         anchorPointY="0.5" src="Resources/snow_packer.plist/m_indicator2.png"/>
            <LabelTTF positionType="LeftBottom" width="200" height="50" positionX="303.0" positionY="1177.0" anchorPointX="0.5"
                      anchorPointY="0.5" text="分数:" fontSize="30" vAlign="Center" hAlign="Top" color="#ffff3219"
                      visible="false"/>
            <LabelBMFont positionType="LeftBottom" width="40" height="40" positionX="241.0" positionY="1068.0" anchorPointX="0.5"
                         anchorPointY="0.5" src="Resources/fonts/score.fnt" text="123" scaleX="1" scaleY="1"
                         var="scoreLabel" target="Doc" visible="false"/>
            <Sprite positionType="LeftBottom" width="113.0" height="120.0" positionX="350.0" positionY="747.0" anchorPointX="0.5"
                                         anchorPointY="0.5" src="Resources/snow_packer.plist/m_monster_g_0001.png"
                                         var="monster" target="Doc"/>
            <Menu positionType="LeftBottom" width="100" height="100" positionX="608.0" positionY="1166.0" anchorPointX="0.5"
                  anchorPointY="0.5">
                <MenuItem positionType="LeftBottom" width="107" height="112" positionX="13.0" positionY="18.0"
                          anchorPointX="0.5"
                          anchorPointY="0.5" normalImage="Resources/snow_packer.plist/m_bun_pause_s.png"
                          onClick="onPauseClicked" target="Doc"/>
            </Menu>
        </Sprite>
        <Menu positionType="LeftBottom" width="40" height="40" positionX="371.0" positionY="299.0" anchorPointX="0.5"
              anchorPointY="0.5" scaleX="2.4" scaleY="1.725" visible="false">
            <MenuItem positionType="LeftBottom" width="40" height="40" positionX="0" positionY="0"
                      anchorPointX="0"
                      anchorPointY="0"
                      normalImage="Resources/CloseNormal.png"
                      selectedImage="Resources/CloseSelected.png" disabledImage="Resources/CloseSelected.png"
                      target="Doc" onClick="onExitClicked"/>
        </Menu>
    </Layer>


</Document>

MainLayer.js

//
// CleanerScoreScene class
//

var MainLayer = function () {
    cc.log("MainLayer")
    this.scoreLabel = this.scoreLabel || {};
    this.monster = this.monster || {};
    this.score = 123;
};

MainLayer.prototype.onDidLoadFromCCB = function () {
    if (sys.platform == 'browser') {
        this.onEnter();
    }
    else {
        this.rootNode.onEnter = function () {
            this.controller.onEnter();
        };
    }

    this.rootNode.schedule(function (dt) {
        this.controller.onUpdate(dt);
    });

    this.rootNode.onExit = function () {
        this.controller.onExit();
    };

    this.rootNode.onTouchesBegan = function (touches, event) {
        this.controller.onTouchesBegan(touches, event);
        return true;
    };

    this.rootNode.onTouchesMoved = function (touches, event) {
        this.controller.onTouchesMoved(touches, event);
        return true;
    };
    this.rootNode.onTouchesEnded = function (touches, event) {
        this.controller.onTouchesEnded(touches, event);
        return true;
    };
    this.rootNode.setTouchEnabled(true);
};

MainLayer.prototype.onEnter = function () {
    var flowerParticle = cc.ParticleSystem.create("Resources/particles/flower.plist");
    flowerParticle.setAnchorPoint(cc.p(0.5, 0.5));
    flowerParticle.setPosition(cc.p(60, 160));
    flowerParticle.setPositionType(1);
    this.monster.addChild(flowerParticle);

    cc.AudioEngine.getInstance().playMusic("Resources/sounds/bg_music.mp3", true);
}

MainLayer.prototype.monsterMove = function (x, y) {
    this.monster.stopAllActions();
    cc.AnimationCache.getInstance().addAnimations("Resources/snow_frame.plist");//添加帧动画文件
    var action0 = cc.Sequence.create(cc.MoveTo.create(5, cc.p(x, y)));  //向前移动
    var actionFrame = cc.Animate.create(cc.AnimationCache.getInstance().getAnimation("monster"));   //获取帧动画
    var action1 = cc.Repeat.create(actionFrame, 90000);
    var action2 = cc.Spawn.create(action0, action1); //同步动画
    this.monster.runAction(action2);
}

MainLayer.prototype.createParticle = function (name, x, y) {
    var particle = cc.ParticleSystem.create("Resources/particles/" + name + ".plist");
    particle.setAnchorPoint(cc.p(0.5, 0.5));
    particle.setPosition(cc.p(x, y));
    particle.setPositionType(1);
    particle.setDuration(3);
    this.rootNode.addChild(particle);
}


MainLayer.prototype.onUpdate = function (dt) {
    this.score += dt;
    this.scoreLabel.setString(Math.floor(this.score));
}

MainLayer.prototype.onExitClicked = function () {
    cc.log("onExitClicked");
}


MainLayer.prototype.onExit = function () {
    cc.log("onExit");
}

MainLayer.prototype.onRenewClicked = function () {  //返回到开始界面
    cc.Director.getInstance().resume();
    cc.log("onRenewClicked");
    cc.BuilderReader.runScene("", "StartLayer");
}

MainLayer.prototype.onSelectClicked = function () {  //选关
    cc.Director.getInstance().resume();
    cc.log("onListClicked");
    cc.BuilderReader.runScene("", "GameSelectLayer");
}

MainLayer.prototype.onReplayClicked = function () {  //新游戏
    cc.Director.getInstance().resume();
    cc.log("onReplayClicked");
    cc.BuilderReader.runScene("", "MainLayer");
}

/*MainLayer.prototype.onReturnClicked = function () {  //返回游戏
 cc.log("onReturnClicked");
 if (this.paused) {
 if (this.pausedLayer) {
 this.pausedLayer.removeFromParent();
 this.pausedLayer = null;
 }
 cc.Director.getInstance().resume();
 this.paused = false;
 }
 }*/

MainLayer.prototype.onPauseClicked = function () {   //点击暂停游戏
    this.pausedLayer = cc.BuilderReader.loadAsNodeFrom("", "PauseLayer", this);
    this.pausedLayer.setPosition(cc.p(0, 0));
    this.pausedLayer.setZOrder(200);
    this.rootNode.addChild(this.pausedLayer);
    this.paused = true;
    cc.AudioEngine.getInstance().stopMusic();
    cc.Director.getInstance().pause();
}

MainLayer.prototype.onTouchesBegan = function (touches, event) {
    var loc = touches[0].getLocation();
}

MainLayer.prototype.onTouchesMoved = function (touches, event) {
    cc.log("onTouchesMoved");
}

MainLayer.prototype.onTouchesEnded = function (touches, event) {
    cc.log("onTouchesEnded");
    var loc = touches[0].getLocation();
    cc.AudioEngine.getInstance().playEffect("Resources/sounds/bomb.mp3", false);
    this.monsterMove(loc.x, loc.y);
    this.createParticle("around", loc.x, loc.y);
}





暂停界面;


PauseLayer.ccbx

<?xml version="1.0" encoding="UTF-8"?>

<Document
        jsControlled="true"
        jsController=""
        resolution="default"
        >

    <Resolutions>
        <Resolution centeredOrigin="false" ext="iphone" height="1280" width="720" name="default" scale="1"/>
        <Resolution centeredOrigin="false" ext="iphone" height="720" width="1280" name="default1" scale="1"/>
    </Resolutions>

    <Animations>
        <Animation autoPlay="true"
                   id="0"
                   name="Default Timeline"
                   length="10"
                   chainedId="0"
                   offset="0.0"
                   position="0.0"
                   resolution="30"
                   scale="128">
            <CallbackChannel>
            </CallbackChannel>
            <SoundChannel>
            </SoundChannel>
        </Animation>

    </Animations>

    <Layer
            positionX="0" positionY="0"
            width="100" height="100" sizeType="Percent"
            anchorPointX="0.5" anchorPointY="0.5" ignoreAnchorPoint="true"
            scaleX="1" scaleY="1"
            touchEnabled="true" positionType="LeftBottom" target="Owner" mouseEnabled="true" keyboardEnabled="true">
        <LayerColor positionType="LeftBottom" width="720" height="1280" positionX="0" positionY="0" anchorPointX="0"
                    anchorPointY="0" color="#5757565a" touchEnabled="true" mouseEnabled="true" keyboardEnabled="true"/>
        <Sprite positionType="LeftBottom" width="587.0" height="834.0" positionX="362.0" positionY="645.0"
                anchorPointX="0.5"
                anchorPointY="0.5" src="Resources/s_bg_grade.png">
        <!--<LayerColor positionType="LeftBottom" width="600" height="800" positionX="66.0" positionY="234.0"
                    anchorPointX="0"
                    anchorPointY="0" color="#ffff55fd" touchEnabled="true" mouseEnabled="true" keyboardEnabled="true"
                    accelerometerEnabled="true">-->
            <Sprite positionType="LeftBottom" width="113.0" height="120.0" positionX="307.0" positionY="588.0"
                    anchorPointX="0.5"
                    anchorPointY="0.5" src="Resources/snow_packer.plist/m_monster_g_0002.png"
                    scaleX="2" scaleY="2"/>
            <Menu positionType="LeftBottom" width="40" height="40" positionX="281.0" positionY="259.0"
                  anchorPointX="0.5"
                  anchorPointY="0.5">
                <MenuItem positionType="LeftBottom" width="99" height="94" positionX="-136.0" positionY="-4.0"
                          anchorPointX="0.5" anchorPointY="0.5" normalImage="Resources/snow_packer.plist/m_bun_back.png"
                          target="Owner" onClick="onRenewClicked"
                          selectedImage="Resources/snow_packer.plist/m_bun_back.png"/>
                <MenuItem positionType="LeftBottom" width="99" height="94" positionX="30.0" positionY="-3.0"
                          anchorPointX="0.5"
                          anchorPointY="0.5" normalImage="Resources/snow_packer.plist/m_bun_again.png" target="Owner"
                          onClick="onReplayClicked" selectedImage="Resources/snow_packer.plist/m_bun_again.png"/>
                <MenuItem positionType="LeftBottom" width="99" height="94" positionX="201.0" positionY="-1.0"
                          anchorPointX="0.5" anchorPointY="0.5" normalImage="Resources/snow_packer.plist/m_bun_list.png"
                          target="Owner" onClick="onSelectClicked"
                          selectedImage="Resources/snow_packer.plist/m_bun_list.png"/>
            </Menu>
        <!--</LayerColor>-->
        </Sprite>

    </Layer>


</Document>

最后主函数Main,js,Main.xml;

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Game</string>
	<key>language</key>
	<string>Javascript</string>
	<key>main</key>
	<string>main.js</string>
	<key>designWidth</key>
	<string>720</string>
	<key>designHeight</key>
	<string>1280</string>
	<key>designPolicy</key>
	<string>NO_BORDER</string>
	<key>viewWidth</key>
	<string>360</string>
	<key>viewHeight</key>
	<string>640</string>
	<key>debug</key>
	<string>false</string>
</dict>
</plist>

if (sys.platform == 'browser') {
    var require = function (file) {
        var d = document;
        var s = d.createElement('script');
        s.src = file;
        d.body.appendChild(s);
    }
} else {
    require("jsb.js");
}

cc.debug = function (msg) {
    cc.log(msg);
}

cc.BuilderReader.replaceScene = function (path, ccbName) {
    var scene = cc.BuilderReader.loadAsSceneFrom(path, ccbName);
    cc.Director.getInstance().replaceScene(scene);
    return scene;
}

cc.BuilderReader.loadAsScene = function (file, owner, parentSize) {
    var node = cc.BuilderReader.load(file, owner, parentSize);
    var scene = cc.Scene.create();
    scene.addChild(node);
    return scene;
};

cc.BuilderReader.loadAsSceneFrom = function (path, ccbName) {
    cc.BuilderReader.setResourcePath(path + "/");
    return cc.BuilderReader.loadAsScene(path + "/" + ccbName);
}

cc.BuilderReader.loadAsNodeFrom = function (path, ccbName, owner) {
    cc.BuilderReader.setResourcePath(path + "/");
    return cc.BuilderReader.load(path + "/" + ccbName, owner);
}

cc.BuilderReader.runScene = function (module, name) {
    var director = cc.Director.getInstance();
    var scene = cc.BuilderReader.loadAsSceneFrom(module, name);
    var runningScene = director.getRunningScene();
    if (runningScene === null) {
        cc.log("runWithScene");
        director.runWithScene(scene);
    }
    else {
        cc.log("replaceScene");
        director.replaceScene(scene);
    }
}

var ccb_resources = [
    {type: 'image', src: "Resources/HelloWorld.png"},
    {type: 'image', src: "Resources/CloseNormal.png"},
    {type: 'image', src: "Resources/CloseSelected.png"}
];

require("MainLayer.js");
require("StartLayer.js");
require("GameSelectLayer.js");

if (sys.platform == 'browser') {

    var Cocos2dXApplication = cc.Application.extend({
        config: document['ccConfig'],
        ctor: function () {
            this._super();
            cc.COCOS2D_DEBUG = this.config['COCOS2D_DEBUG'];
            cc.initDebugSetting();
            cc.setup(this.config['tag']);
            cc.AppController.shareAppController().didFinishLaunchingWithOptions();
        },
        applicationDidFinishLaunching: function () {
            var director = cc.Director.getInstance();
            // director->enableRetinaDisplay(true);
            // director.setDisplayStats(this.config['showFPS']);
            // set FPS. the default value is 1.0/60 if you don't call this
            director.setAnimationInterval(1.0 / this.config['frameRate']);
            var glView = director.getOpenGLView();
            glView.setDesignResolutionSize(1280, 720, cc.RESOLUTION_POLICY.SHOW_ALL);
            cc.Loader.preload(ccb_resources, function () {
                cc.BuilderReader.runScene("", "StartLayer");
            }, this);
            return true;
        }
    });
    var myApp = new Cocos2dXApplication();
} else {
    cc.BuilderReader.runScene("", "StartLayer");
}



下一篇文章 我会介绍cocos2d-x  editor的其他特性    笔者(李元友)

资料来源:cocos2d-x  editor


cocos2d-x“无法打开源文件”

这一周开始学习cocos2d-x,刚开始就碰到了一些问题,新建完工程后,自己给工程添加新的文件,有两种方式: 第一种是使用VS的类向导,让软件帮我们把需要添加的类加入到工程,可以一次把头文件和cp...

Cocos2d-x学习(十):cocos2d-x 2.0版本中CCScrollView的用法

cocos2d-x 2.0版本之后提供了许多控件,其中就包括ScrollView,之前总结过一个简单的ScrollView,但是问题很多,比如必须是全屏,不能是一块区域,而cocos2d-x 2.0中...

五 手游开发神器 cocos2d-x editor 之贴图(TexturePacker)

这一节主要是介绍cocos2dx editor的贴图功能。cocos2dx editor是开发跨平台的手机游戏工具,运行window系统上,javascript脚本语言,基于cocos2d-x跨平台游...

十 手游开发神器 cocos2d-x editor 之触摸事件

这一节主要是介绍cocos2dx editor的触摸事件,让小怪物跟随移动。cocos2dx editor是开发跨平台的手机游戏工具,运行window系统上,javascript脚本语言,基于coco...

十一 手游开发神器 cocos2d-x editor 之音乐和音效

这一节主要是介绍cocos2dx editor的背景音乐和音效。cocos2dx editor是开发跨平台的手机游戏工具,运行window系统上,javascript脚本语言,基于cocos2d-x跨...

三 手游开发神器 cocos2d-x editor 之基础工具 intellij idea

intellij idea 13 注册序列号:亲测有效  Orefa      00066-FEIQE-EEZDY-D9PBH-Z9W0E-SPJS1makeapp   00820-K2S8N-...

手游开发神器 cocos2d-x editor 教程聚合和代码下载(持续更新中)

——————————————游戏基础教程篇—————————————已完成————————— 一 cocos2d-x editor工具下载和基础教程JS篇: 一 手游开发神...
  • dj0379
  • dj0379
  • 2014年05月18日 14:30
  • 2796

七 手游开发神器 cocos2d-x editor 之图片字体(LabelBMFont)

这一节主要是介绍cocos2dx editor的图片字体功能,实现分数不停的刷新效果。cocos2dx editor是开发跨平台的手机游戏工具,运行window系统上,javascript脚本语言,基...

八 手游开发神器 cocos2d-x editor 之动画和帧动画

这一节主要是介绍cocos2dx editor的动画和帧动画,让小怪物摇摇晃晃的向前行走。cocos2dx editor是开发跨平台的手机游戏工具,运行window系统上,javascript脚本语言...

六 手游开发神器 cocos2d-x editor 之场景切换

接着上一节,我们已经创建了一个主游戏场景MainLayer,现在我们需要创建一个开始场景StartLayer,包括StartLayer.ccbx和StartLayer.js两个文件,点击StartLa...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:十四 手游开发神器 cocos2d-x editor 之串联游戏流程
举报原因:
原因补充:

(最多只允许输入30个字)