我定义了个触摸监听器 获取touch坐标 加载精灵并使其在0,8s内move to 到touch 的坐标 为了让精灵到达后消失 写了个定时器函数scheduleOnce 0.8s后会remove精灵 但是如果我连续点击2下 就是在上一个精灵还没到达之前 即0.8s以内 再点击一下 上一个精灵的定时器函数好像就不会执行了 是新的touch事件中止了上一个的定时器函数吗? 求大神解决
bool HelloWorld::TouchBegan(Touch* touch,Event* event) {
bullet_num++;
log("touch!,%f %f %d",touch->getLocation().x,touch->getLocation().y,bullet_num);
double angle = atan2(touch->getLocation().y,touch->getLocation().x);
auto sprite1 = Sprite::create("bullet.jpg");
sprite1->setTag(101);
sprite1->setScale(0.25);
sprite1->setPosition(Vec2::ZERO);
sprite1->setRotation(-angle*180/M_PI);
this->addChild(sprite1);
auto move = MoveTo::create(0.8f,Vec2(touch->getLocation().x,touch->getLocation().y));
sprite1->runAction(move);
this->scheduleOnce(schedule_selector(HelloWorld::Remove),0.8f);
return true;
}
void HelloWorld::Remove(float delay) {
this->removeChildByTag(101);
log("%d removed!",bullet_num);
}
```