醒着☆☆

H5 Laya Native Game

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

要求:

右侧的可以拖拽

右侧的需要放到正确的对应区可自动吸附

否则释放鼠标回到原位

当所有右侧都放到了对应的左侧

出现成功的画面界面如图:

绿色的三个 实例名称:a0 a1 a2

蓝色的三个 实例名称:b0 b1 b2

代码如下:

 

 1stop();
 2var total:Number = 0;
 3for (var i:Number = 0; i<3; i++{
 4    this["b"+i].id = i;
 5    //存取编号用于判断是否拖到了目的地
 6    this["b"+i].x = this["b"+i]._x;
 7    this["b"+i].y = this["b"+i]._y;
 8    //注意左面的是x 右面的是 _x
 9    //.x与.y来存取初始位置,后面的程序
10    //在判断没有拖到正确的位置回复位
11    this["b"+i].onPress = function() {
12        this.startDrag();
13        this.hit = false;
14    }
;
15    this["b"+i].onRelease = function() {
16        this.stopDrag();
17        for (var j:Number = 0; j<3; j++{
18            this._parent["a"+j].id = j;
19            if (this.hitTest(this._parent["a"+j])) {
20                this.crt = this._parent["a"+j].id;
21                this.hit = true;
22            }

23        }

24        if (this.crt == this.id && this.hit) {
25            //如果碰到了左侧,且位置对了
26            this._x = this._parent["a"+this.id]._x;
27            this._y = this._parent["a"+this.id]._y;
28            //让蓝色的方框的坐标和绿色的一样
29            total++;
30            //拖动正确的数目 要增加
31        }
 else {
32            this._x = this.x;
33            this._y = this.y;
34            //没有拖动正确复位
35        }

36        if (total == 3{
37            txt.text = "全部正确";
38        }

39    }
;
40}

源文件下载

 

 

naiking

我在醒着

posted on 2008-08-28 09:04  醒着/☆☆  阅读(273)  评论(0编辑  收藏  举报