createjs之easeljs【游戏围住神经猫】

本文介绍如何借助CreateJS库中的EaselJS模块来开发一款名为‘围住神经猫’的游戏。内容涵盖HTML文件的引入设置、EaselJS的基本用法以及游戏逻辑的实现。
摘要由CSDN通过智能技术生成


在html文件中引入

<script src="circle.js"></script>	创建圆类
<canvas width="800px" height="800px" id="gameView">您的浏览器不支持</canvas>
<script src="app.js"></script>        游戏逻辑

circle.js文件中
/**
 * Created by Administrator on 2015/3/3.
 */

function Circle(){
    createjs.Shape.call(this);

    this.setCircleType= function (type) {
        this._circleType=type;
        switch (type){
            case Circle.TYPE_UNSELECTED:
                this.setColor("#cccccc");
                break;
            case Circle.TYPE_SELECTED:
                this.setColor("#ff6600");
                break;
            case Circle.TYPE_CAT:
                this.setColor("#0000ff");
                break;
        }
    }

    this.setColor= function (colorString) {
        this.graphics.beginFill(colorString);
        this.graphics.drawCircle(0,0,25);
        this.graphics.endFill();
    }
    this.getCircleType=function(){
        return this._circleType;
    }
    this.setCircleType(1);
}
Circle.prototype = new createjs.Shape();
Circle.TYPE_UNSELECTED=1;
Circle.TYPE_SELECTED=2;
Circle.TYPE_CAT=3;

与看你有多色游戏的rect差别的大,唯一差别就是这里为了app.js更好调用,为每一种颜色定义了一个变量。
Circle.TYPE_UNSELECTED=1;
Circle.TYPE_SELECTED=2;
Circle.TYPE_CAT=3;
</pre>
this.graphics.drawCircle(0,0,25);    画半径为25的圆

app.js文件中
var stage = new createjs .Stage("gameView");
var gameView = new createjs.Container ();
gameView.x=30;
gameView.y=30;   gameView的x,y都移动30的原因是不使最左端最上端的圆只剩一半。

stage.addChild(gameView);

createjs.Ticker.setFPS(30);
createjs.Ticker.addEventListener("tick",stage);

仿照看你有多色的做法,创建了addCircles类
var circleArr=[[],[],[],[],[],[],[],[],[]];  创建二维数组记录棋盘
var currentCat;

function addCircles() {
    for(var indexY=0;indexY<9;indexY++){
       for(var indexX=0;indexX<9;indexX++){
           var c=new Circle();
           gameView.addChild(c);
           circleArr[indexX ][indexY]=c;     indexX和indexY记录棋盘的第几行第几个,把它记录到数组中
           c.indexX=indexX;
           c.indexY
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值