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

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);

}

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

其实道理都一样……你非要用sprite,我就写了一个,真的只有监听麻烦了

var MyCard=cc.Sprite.extend({
	type:null,
	ctor:function(type,res){
		this.type=type;
		this._super(res);
		cc.eventManager.addListener({
			swallowTouches: true,
			event: cc.EventListener.TOUCH_ONE_BY_ONE,
			onTouchBegan: this.onTouchBegan.bind(this)
			
		}, this);
	},
	onTouchBegan:function(touch, event){
		var target = event.getCurrentTarget();
		var locationInNode = target.convertToNodeSpace(touch.getLocation());
		var s = target.getContentSize();
		var rect = cc.rect(0, 0, s.width, s.height);
		if (cc.rectContainsPoint(rect, locationInNode)){
			cc.log(this.type);
			return true;
		}
			return false;
	}
})
var TouchTestLayer=cc.Layer.extend({
	ctor:function(){
		this._super();
		var card=new MyCard(1,res.feng_png);
		card.setPosition(500,200);
		this.addChild(card);
		var card2=new MyCard(2,res.lei_png);
		card2.setPosition(520,200);
		this.addChild(card2);
	}
});

兄弟不好意思哈!!!我初学,好多东西都还在学,我想一个问题一个问题都高明白!!!!

而且你的是JS!我是c++,虽然大同小异,但也还有些不懂啊!!!!

所以我之前是先说的思路而不是直接上代码的啊。宗旨就是让牌自己监听自己,不要在外界的for循环里手动做监听。这里用到的知识点只有继承,知道思路之后代码怎么实现其实根本不重要

自己监听自己????怎么做???没懂 !!!!!

怎么做不是写给你了吗= =,自己写一个类继承sprite(推荐是imageView),然后在那个类中写监听

你这么说我就明白了!!!!谢谢!!!