Flash 拼图游戏中拼图块的位置
我有一个4*4的网格。我有 16 个 MovieClip 分散在网格中。每个MovieClip都是40*40并且可以拖动。用户可以将影片剪辑拖放到网格中。每个剪辑都有正确的位置。例如,对于
剪辑 0:x=0,y=0
剪辑 1:x=40,y=0
剪辑 2:x=120,y=0
剪辑 3:x=160,y=0
剪辑 15:x=160, y=160
当所有剪辑都处于正确位置时游戏结束。因此很容易检查游戏是否结束。使用循环和 ENTER_FRAME 监视所有剪辑的位置。
有一个小问题我无法解决。当用户拖动剪辑时,无论正确与否,它都会捕捉到网格中的位置。在这种情况下,可捕捉位置将为 40 的倍数。两个剪辑可能会捕捉到一个位置,必须避免这种情况。如果我在 (40,120) 处放置了一个剪辑,我就不应该再在那里放置另一个 MovieClip。实际上,我应该能够得到一些指示,告诉我这个位置已被占用。
使用指示我将使影片剪辑返回到原始位置。
这怎样才能实现呢。影片剪辑的注册点位于左上角。
I have a 4*4 grid. I have 16 MovieClips scattered around the grid. Each MovieClip is 40*40 and they are draggable. The user can drag and drop the MovieClips into the grid. Each clip has a correct position. For example for
clip 0 : x=0 , y=0
clip 1 : x=40, y=0
clip 2 : x=120 , y=0
clip 3 : x=160 , y=0
clip 15 : x=160 , y=160
The game finishes when all the clips are in correct position. So its easy to check for game over. Use a loop and ENTER_FRAME to monitor the positions of all clips.
There is a small problem I cannot solve. When the user drags a clip it will snap to position in the grid whether it is correct or not. The snappable positions will be multiples of 40 in this case. It is possible for two clips to snapped to a location and this has to be avoided. If I have put a clip at (40,120) I should not be able drop another MovieClip there. In effect I should be able to get some indication telling me that this position is occupied.
Using the indication I will make the MovieClip return to original position.
How can this can be achieved. The registration points of MovieClips are topleft.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
携带一个带有16个字段占用信息的物体。如果存在剪辑,请将适当的属性设置为 true。替代方案:一个巧妙的解决方案是简单地使用 int var 和二进制 sum:
如果前三个位置已被占用,则总和将为
1 + 2 + 4 = 7
。您可以这样测试字段是否被占用:
当用户释放鼠标时,您需要计算剪辑将捕捉到的位置。使用您的对象或二进制总和检查该字段是否被占用。如果是这样,请将剪辑的位置重置为其之前的状态。如果该字段仍然空闲,则将该字段添加到对象或二进制和中:
如果剪辑离开其字段:
摘要:
Carry an object with information about the occupation of the 16 fields. If a clip is present, set the appropriate property to true. Alternative: A nifty solution is to simply use an int var and a binary sum:
If the first three positions are occupied, your sum will be
1 + 2 + 4 = 7
.You test if a field is occupied like this:
At the time the user releases the mouse you need to calculate the position the clip will snap into. Check if the field is occupied using your object or the binary sum thing. If so, reset the position of the clip to its former state. If the field is still free, you add the field to your object or the binaray sum:
If a clip leaves its field:
Summary: