检测我触摸的延长弹簧
Detecting which extended sprited i touched
我想检测我触摸的卡的对象。卡是自定义类,它扩展了可可精灵。
我想在卡上调用成员方法。类似的东西:如果(目标是卡)target.opencard();
非常感谢您。
主要班级主体
bool HelloWorld::init()
{
... some init code, generating card arrays, shuffling
// draw memory cards
int count = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
auto card = Card::createCard();
card->customInit(cardsPictures[count]);
this->addChild(card);
card->setPosition(100 + i*100, 600 - j*100);
count++;
}
}
// register event listener
auto touchListener = EventListenerTouchOneByOne::create();
touchListener->onTouchBegan = CC_CALLBACK_2(HelloWorld::onTouchBegan, this);
touchListener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
touchListener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved, this);
touchListener->onTouchCancelled = CC_CALLBACK_2(HelloWorld::onTouchCancelled, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
return true;
}
bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
{
auto target = event->getCurrentTarget();
if (target is Card) target.openCard(); // not working
return true;
}
(target is Card)
对我来说看起来不像C 。它是什么 ?:D
首先:目标是指针吗?如果是这样:
target->openCard(); // instead of target.openCard();
无论如何,如果要在确定的对象上调用类型卡的方法,也许应该这样做:
Card* myCard = static_cast<Card*>(target);
myCard->openCard();
说实话,除非您实际发布相关代码,否则任何人都很难为您提供帮助。卡甚至看起来像什么?(我不在乎!XD)
相关文章:
- 使用CMake检测支持的C++标准
- 当套接字连接断开时检测C/C++Unix
- C/C++预处理器是否可以检测一些编译器选项
- WMI检测进程创建事件-c++
- 基于树莓pi的tensorflow lite量化ssd目标检测
- 下面是我为检测链接列表中的循环而制作的代码
- 落砂模拟碰撞检测C++和SFML
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- 为什么C++编译器没有检测到正确声明的类?
- 检测win32服务创建和删除的最佳方法
- 正在LLVM中检测整数比较条件
- 如何在鼠标挂钩过程中检测拖动
- 位移操作和位掩码未检测到重复字符
- 检测 OpenCV C++窗口上的触摸
- 检测我触摸的延长弹簧
- 如何检测到插入/输出Oculus触摸控制器
- 检测触摸 Cocos2d-x
- 正在检测屏幕的触摸属性
- SpriteBatchNode的触摸检测
- 如何检测何时在触摸设备上显示键盘?