Android 遍历常量std::vector<;cocos2d::触摸屏>&;touch-Cocos2dx

Android 遍历常量std::vector<;cocos2d::触摸屏>&;touch-Cocos2dx,android,c++,cocos2d-x,cocos2d-x-3.0,Android,C++,Cocos2d X,Cocos2d X 3.0,我想使用multitouch并编写所需的事件和侦听器。现在我想获得Touch sprite,为此,我应该获得触摸点的位置,但我不知道如何将其写入以下代码: void Break::onTouchesBegan(const std::vector<Touch*>& touch, Event* event) { What should I write here for getting touched sprite? } void Break::onTouchesBega

我想使用multitouch并编写所需的事件和侦听器。现在我想获得Touch sprite,为此,我应该获得触摸点的位置,但我不知道如何将其写入以下代码:

void Break::onTouchesBegan(const std::vector<Touch*>& touch, Event* event)
{
    What should I write here for getting touched sprite?
}
void Break::onTouchesBegan(const std::vector&touch,Event*Event)
{
我应该在这里写些什么来触碰雪碧?
}

添加侦听器时,请确保使用了场景图优先级


event->target()将为您提供精灵

如果您的场景正在收听事件,则event->target()将为您提供基本节点,而不是被触摸的节点。在这种情况下,您需要某种形式的触摸检测(通过检查RECT或执行radiustarget()),但您仍然需要某种形式的碰撞检测,以便触摸事件系统知道触摸是否成功。据我所知,cocos不会为您执行这些检查。 只是一个例子(你的逻辑可能有所不同——例如,如果触摸中至少有一个与它的边界框或其他东西发生碰撞),你可以考虑触摸来触摸你的对象:

void Break::onTouchesBegan(const std::vector&touch,Event*Event)
{
//如果至少有一次触摸没有触摸到物体,那么就没有触摸
用于(自动和t:触摸){
如果(!碰撞检查){
返回false;
}
}
返回true;
//或
//如果至少有一次触碰对象,则存在触碰
用于(自动和t:触摸){
如果(碰撞检查){
返回true;
}
}
返回false;
}
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;
}