• 一个游戏的例子


    一、创建一个场景,需要如下步骤:

    1.在src目录下新建一个StartScene.js空文件。

    2.打开project.json,在jsList字段加入StartScene.js的路径。
    "jsList" : [
    "src/resource.js",
    "src/StartScene.js"
    ]
    注:project.json中的jsList用于配置项目所使用的js文件。

    3.打开StartScene.js文件,加入下面的场景创建代码。
    var StartLayer = cc.Layer.extend({
    ctor:function () {
    this._super();

    var size = cc.winSize;

    var helloLabel = new cc.LabelTTF("Hello World", "", 38);
    helloLabel.x = size.width / 2;
    helloLabel.y = size.height / 2;
    this.addChild(helloLabel);

    return true;
    }
    });

    var StartScene = cc.Scene.extend({
    onEnter:function () {
    this._super();
    var layer = new StartLayer();
    this.addChild(layer);
    }
    });
    二、添加背景图及其他元素

    1.下面代码添加的startscene.js的方法中

    //add 背景图
    this.bgSprite = new cc.Sprite(res.BackGround_png);
    this.bgSprite.attr({
    x: size.width / 2,
    y: size.height / 2,
    });
    this.addChild(this.bgSprite, 0);

    2.将背景图在resource文件中添加
    3.在main中修改图显示的的大小
    cc.view.setDesignResolutionSize(1200, 700, cc.ResolutionPolicy.SHOW_ALL);
    3.添加按钮

    三、我们添加ball的消失动画
    1.首先添加一个ball,添加ball的时候,我因为下面代码的sprite的S小写了,导致运行是黑屏

    // add ball

    this.ball = new cc.Sprite(res.Ball01_png);
    this.ball.attr({
    x: size.width / 2,
    y: size.height / 2,
    });
    this.addChild(this.ball, 1);

    新问题:图片消失,但没显示动画

  • 相关阅读:
    Nth Highest Salary
    第二高的薪水
    组合两个表
    牛客(66)机器人的运动范围
    牛客(65)矩阵中的路径
    牛客(64)滑动窗口的最大值
    牛客(63)数据流中的中位数
    牛客(62)二叉搜索树的第k个结点
    牛客(61)序列化二叉树
    mybits(2)增删改查
  • 原文地址:https://www.cnblogs.com/fenr9/p/5183449.html
Copyright © 2020-2023  润新知