简体   繁体   English

使用Kinetic.js为矩形创建放置区域

[英]Create a drop area for a rectangle with Kinetic.js

Im creating a "word" game, the objective is drag a character (a rectangle), into the correct word space (another rectangle), if the user drop a character at a wrong space, the character will return to the original point. 在创建“单词”游戏时,目标是将一个角色(一个矩形)拖到正确的单词空间(另一个矩形)中,如果用户将角色放置在错误的位置,该角色将返回到原始位置。

During the drag move, i want to detect if the object is over a word space to contrast it. 在拖动移动期间,我想检测对象是否在单词空间上方以进行对比。 And if the user drop it, insert the character at the correct place... 如果用户放下它,请在正确的位置插入字符...

How can i detect if the user is dropping the character at the correct place? 如何检测用户是否将字符放置在正确的位置? Collision Detect? 碰撞检测? Have it any event to detect if an object is over other object? 是否有任何事件可以检测一个对象是否在另一个对象之上?

I need just the guide lines to detect it. 我只需要指导线即可检测到它。

Maybe what you want is the getIntersections() method ( docs ), it will return the shapes underneath a specific point. 也许您想要的是getIntersections()方法( docs ),它将返回特定点下方的形状。

You could use this to build your own collision detection, ie, call getIntersections() on each corner of the character rectangle and see what shapes you hit. 您可以使用它来构建自己的碰撞检测,即,在字符矩形的每个角上调用getIntersections()并查看击中的形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM