我正在用as3做一个益智游戏,我已经完成了。我将一个位图分成8个部分,我将它们转换成mc,我可以用鼠标移动它们。
我也做了一个拼图板,拼图的碎片掉在那里。现在我如何做一个拼图解决方案,比如当拼图碎片按正确的顺序排列时,整个位图就应该被显示出来。
谢谢您的关注
发布于 2011-10-27 18:14:23
为什么不将mcs位置存储在一个点数组中?
这样,无论mcs在板上的哪个位置,都可以很容易地将它们补间到合适的位置。
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之后,我假设您在该阶段已经有了难题的解决方案。
如果是,那么您需要在它们有机会被移动之前存储这些块的当前位置。
实际上,这意味着在实际存储位置之前不要添加事件侦听器。
//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...
}https://stackoverflow.com/questions/7913841
复制相似问题