首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >游戏解决方案ActionScript 3

游戏解决方案ActionScript 3
EN

Stack Overflow用户
提问于 2011-10-27 17:10:30
回答 1查看 251关注 0票数 1

我正在用as3做一个益智游戏,我已经完成了。我将一个位图分成8个部分,我将它们转换成mc,我可以用鼠标移动它们。

我也做了一个拼图板,拼图的碎片掉在那里。现在我如何做一个拼图解决方案,比如当拼图碎片按正确的顺序排列时,整个位图就应该被显示出来。

谢谢您的关注

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-27 18:14:23

为什么不将mcs位置存储在一个点数组中?

这样,无论mcs在板上的哪个位置,都可以很容易地将它们补间到合适的位置。

代码语言:javascript
复制
 var positions:Array = [ new Point(mc1.x , mc1.y), .... , new Point(mcn.x , mc1.n), ];

 //assuming that this code is run from 
 // the mcs container and that this container
 // doesn't have any other children
 for( var i:int ; i < this.numChildren ; ++i )
 {
     //provided that the MCs are on 
     //the right order in the Display List
     var mc:MovieClip = this.getChildAt(i) as MovieClip;

     //no tween here but you get the idea...
     mc.x = positions[i].x; 
     mc.y = positions[i].y; 
 }

在您拆分位图并将其转换为MovieClips之后,我假设您在该阶段已经有了难题的解决方案。

如果是,那么您需要在它们有机会被移动之前存储这些块的当前位置。

实际上,这意味着在实际存储位置之前不要添加事件侦听器。

代码语言:javascript
复制
 //instantiate the Array
 var positions:Array = [];
 for(var i:int ; i < this.numChildren; ++i )
 {
    // add the mcs positions
    var positions[i] = new Point ( this.getChildAt(i).x , this.getChildAt(i).y );

    //you could add your Mouse Event listener here...
 }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7913841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档