zoukankan      html  css  js  c++  java
  • 一个游戏的例子

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

    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);

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

  • 相关阅读:
    55域TLV说明
    iOS开发之指定UIView的某几个角为圆角
    常逛的博客
    猿题库 iOS 客户端架构设计
    NSData
    base64编码
    RSA算法原理
    无法安装64位版本的office因为在您的pc
    mysql导出导入数据
    设置mysql的字符集
  • 原文地址:https://www.cnblogs.com/fenr9/p/5183449.html
Copyright © 2011-2022 走看看