Egret社区
10银子
本帖最后由 ZHZ 于 2016-4-28 21:49 编辑

下面是用wing建的默认游戏项目代码:
private createGameScene():void {
var sky:egret.Bitmap = this.createBitmapByName("bgImage");
this.addChild(sky);
var stageW:number = this.stage.stageWidth;
var stageH:number = this.stage.stageHeight;
sky.width = stageW;
sky.height = stageH;


var topMask:egret.Shape = new egret.Shape();
topMask.graphics.beginFill(0x000000, 0.5);
topMask.graphics.drawRect(0, 0, stageW, stageH);
topMask.graphics.endFill();
topMask.width = stageW;
topMask.height = stageH;
this.addChild(topMask);


var icon:egret.Bitmap = this.createBitmapByName("egretIcon");
this.addChild(icon);
icon.scaleX = 0.55;
icon.scaleY = 0.55;
icon.anchorOffsetX = icon.width / 2;
icon.anchorOffsetY = icon.height / 2;
icon.x = stageW / 2;
icon.y = stageH / 2 - 60;


var title:egret.TextField = new egret.TextField();
title.textColor = 0xffffff;
title.textAlign = "center";
title.text = "一个动作,策略,对战游戏";
title.size = 25;
title.x = stageW - title.width >> 1;
title.y = ( stageH - title.height >> 1)+50 ;
this.addChild( title);


var textfield:egret.TextField = new egret.TextField();
this.addChild(textfield);
textfield.alpha = 0;
textfield.width = stageW;
textfield.textAlign = egret.HorizontalAlign.CENTER;
textfield.x = 0;
textfield.y = stageH / 2 + 100;
this.textfield = textfield;

//以下是我写的代码
var btn1: Button = new Button();
this.addChild( btn1 );
//以上是我写的代码


//根据name关键字,异步获取一个json配置文件,name属性请参考resources/resource.json配置文件的内容。
// Get asynchronously a json configuration file according to name keyword. As for the property of name please refer to the configuration file of resources/resource.json.
RES.getResAsync("description", this.startAnimation, this)
}

下面是我定义的button类:

/**
*
* @author
*操作按钮类
*/
class Button extends egret.Sprite{

public constructor() {
this.touchEnabled = true;
super();
var btnX: number = 100;
var btnY: number = 700;
var left: egret.Shape = new egret.Shape();
var up: egret.Shape = new egret.Shape();
var right: egret.Shape = new egret.Shape();
this.draw;
this.move;

}
private draw( left: egret.Shape, up: egret.Shape, right: egret.Shape,btnX,btnY) {
left.graphics.beginFill( 0x000000 );
left.graphics.drawCircle( btnX, btnY, 30 );
left.graphics.endFill();

up.graphics.beginFill( 0x000000 );
up.graphics.drawCircle( 1.3*btnX,0.8*btnY,30 );
up.graphics.endFill();

right.graphics.beginFill( 0x000000 );
right.graphics.drawCircle( 2*btnX, btnY, 30 );
right.graphics.endFill();


}
private move( left: egret.Shape, up: egret.Shape, right: egret.Shape, btnX, btnY) {
left.addEventListener( egret.TouchEvent.TOUCH_MOVE, function ( event ) {
this.stage.x += 1;
},this)
}
}


在 createGameScene()中的其它代码都有效果,我写的代码也没有报错,这是怎么回事?求解


最佳答案

查看完整内容

public constructor() { super(); this.touchEnabled = true; var btnX: number = 100; var btnY: number = 700; var left: egret.Shape = new egret.Shape(); var up: egret.Shape = new egret.Shape(); var right: egret.Shape = new egret.Shape(); this.addChild(left); this.addChild(up); this.addChild(right); this. ...
分享到 :
0 人收藏

3 个回复

倒序浏览
trackway  略有小成 | 2016-4-28 21:39:06
    public constructor() {      
        super();
        this.touchEnabled = true;
        var btnX: number = 100;
        var btnY: number = 700;
        var left: egret.Shape = new egret.Shape();
        var up: egret.Shape = new egret.Shape();
        var right: egret.Shape = new egret.Shape();
        this.addChild(left);
        this.addChild(up);
        this.addChild(right);
        this.draw(left,up,right, btnX,btnY);
        this.move(left,up,right,btnX,btnY);
    }
ZHZ  登堂入室 | 2016-4-29 15:11:49
谢谢
sxtaosdo  自成一派 | 2016-4-29 15:32:05
不明觉厉~~~~~~~~~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|京网文[2014]0791-191号|京ICP证150115号|Egret社区 ( 京ICP备14025619号 )

Powered by Discuz! X3.4 © 2001-2019 Comsenz Inc.

返回顶部