如何给sprite添加单击事件
1个回答
展开全部
1.首先头文件定义事件处理的函数原型private:boolonTouchBegan(Touch*tTouch,Event*eEvent);//手指按下事件voidonTouchMoved(Touch*tTouch,Event*eEvent);//手指移动事件voidonTouchEnded(Touch*tTouch,Event*eEvent);//手指离开事件2.实现原型boolShopItem::onTouchBegan(Touch*tTouch,Event*eEvent){ if(sprite->getBoundingBox().containsPoint(tTouch->getLocation())){//判断触摸点是否在目标的范围内 /**这里为事件内容**/ returntrue; }else returnfalse; }}voidShopItem::onTouchMoved(Touch*tTouch,Event*eEvent){/**这里为事件内容**/}voidShopItem::onTouchEnded(Touch*tTouch,Event*eEvent){/**这里为事件内容**/}3.绑定事件autolistener=EventListenerTouchOneByOne::create();listener->onTouchBegan=CC_CALLBACK_2(ShopItem::onTouchBegan,this);listener->onTouchMoved=CC_CALLBACK_2(ShopItem::onTouchMoved,this);listener->onTouchEnded=CC_CALLBACK_2(ShopItem::onTouchEnded,this);this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,sprite);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询