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

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

  • 相关阅读:
    IOS:APP网络状态的检测
    IOS:个人笔记|UI__使用Plist文件来进行数据的读取
    IntelliJ IDEA中项目import与open的区别
    打开电脑分屏
    微服务
    自增主键和UUID
    雪花算法
    使用navicat连接阿里云上mysql
    【vue】报错This dependency was not found
    跨域问题
  • 原文地址:https://www.cnblogs.com/fenr9/p/5183449.html
Copyright © 2011-2022 走看看