Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

大神们帮我看看这个触摸函数怎么破!

$
0
0

@ycdiv 写道:

bool Game::init()
{
for(int a=0;a<13;a++)
{
auto sprite=Sprite::create(*(name+a)) ///name是一个char数组,储存了图片名字!
sprites->setPosition(40+10*a, 80);//精灵依次排列,有重叠部分。
addChild(sprite)
Click(sprite,80)
}

    return true;

}
void Game::Click(*Sprite _sprite, float Y)
{
anto poker = EventListenerTouchOneByOne::create();
//poker->setSwallowTouches(true);//如果设置禁止向下传递触摸,就只有最后一个精灵响应,不设置点击重叠位置,只要那个位置有的精灵都响应了!!!
poker->onTouchBegan = [&](Touch* touch, Event* event1) {
auto sprite = (Sprite*)event1->getCurrentTarget();
auto pos = Director::getInstance()->convertToGL(touch->getLocationInView());
auto zX = sprite->getPositionX();
auto zY = sprite->getPositionY();
bool YorN = sprite->getBoundingBox().containsPoint(pos);
if (YorN)
{
if (zY ==Y){
auto moveto = MoveTo::create(0, Point(zX, Y + 10));
sprite->runAction(moveto);
}
else{
auto moveto = MoveTo::create(0, Point(zX, Y));
sprite->runAction(moveto);
}

    }
    else{
        auto moveto = MoveTo::create(0, Point(zX, Y));
         sprite->runAction(moveto);
    }

    return true; };

_eventDispatcher->addEventListenerWithSceneGraphPriority(poker, _sprite);

}

怎么能点击时只有被点击的精灵响应!!!

帖子: 6

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>