如果你的场景正在监听事件,那么event-> target()会给你基础点头e,而不是那个被触动的人。在这种情况下,您需要某种形式的触摸检测(通过检查矩形,或执行半径< =距离检查,或通过更复杂的算法 - 这一切都取决于您的情况)。
如果您的对象正在侦听事件,那么您可以使用event-> target(),但仍需要某种形式的碰撞检测,以便触摸事件系统知道触摸是否成功。据我所知,科科斯不会为你执行这些检查。 只是一个例子(你的逻辑可能会有所不同 - 例如,你可以考虑触摸被触碰你的对象,如果触摸的至少一个碰撞与它的边框或诸如此类的东西):
void Break::onTouchesBegan(const std::vector<Touch*>& touch, Event* event)
{
//If at least one touch doesn't touch the object - then there is no touch
for(auto& t : touch){
if(!COLLISION_CHECK){
return false;
}
}
return true;
//OR
//If at least one touch touches the object, then there is a touch
for(auto& t : touch){
if(COLLISION_CHECK){
return true;
}
}
return false;
}