未触发OnTouchMove事件
OnTouchMove event not triggered
本文关键字:事件 OnTouchMove 更新时间:2023-10-16
我试图在一个简单的场景中拖放一个精灵。onTouchBegan和onTouchEnded事件会触发,但onTouchMove事件不会触发,为什么?
这是我的代码:
class Test: public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(Test);
bool onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event);
void onTouchMove(cocos2d::Touch *touch, cocos2d::Event *event);
void onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event);
cocos2d::Sprite *catSprite;
cocos2d::Vec2 touchPosition;
};
对于Cpp:
Scene* Test::createScene()
{
auto scene = Scene::create();
auto layer = Test::create();
scene->addChild(layer);
return scene;
}
bool Test::init()
{
if ( !Layer::init() )
{
return false;
}
auto origin = Director::getInstance()->getVisibleOrigin();
auto windowSize = Director::getInstance()->getVisibleSize();
auto background = DrawNode::create();
background->drawSolidRect(origin, windowSize, Color4F(0.6, 0.6, 0.6, 1.0));
this->addChild(background, -1);
auto releaseArea = DrawNode::create();
releaseArea->drawSolidRect(windowSize*0.8,windowSize, Color4F(1.0,0.0,0.0,1.0));
this->addChild(releaseArea);
auto pinfo = AutoPolygon::generatePolygon("cat.png");
catSprite = Sprite::create(pinfo);
catSprite->setPosition(Vec2(windowSize.width*0.1, windowSize.height*0.1));
this->addChild(catSprite,1);
touchPosition.set(0,0);
auto dispatcher = Director::getInstance()->getEventDispatcher();
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(Test::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(Test::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(Test::onTouchEnded, this);
dispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
bool Test::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event) {
cocos2d::log("touch began");
touchPosition = touch->getLocation();
if(catSprite->getBoundingBox().containsPoint(touchPosition))
{
return true;
}
return false;
}
void Test::onTouchMove(cocos2d::Touch *touch, cocos2d::Event *event) {
cocos2d::log("touch moved");
catSprite->setPosition(catSprite->getPosition() + touch->getDelta());
}
void Test::onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event) {
cocos2d::log("touch ended");
}
我从cocos2d::log中得到了正确的开始和结束事件的反馈,但当我测试它时,move事件似乎从未发生过。
事件被称为onTouchMoved,而不是onTouchMove。
谨致问候。我自己
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- 从文本文件中读取时钟时间和事件时间并进行处理
- WMI检测进程创建事件-c++
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 处理闪烁窗口事件
- C++Builder中的OnClick事件签名存在问题
- 跟踪滚动条上的鼠标事件
- 什么是事件表 (wxWidgets)?
- 如何在 MFCaptureEngine 中获取"Camera removed"事件
- 给定顺序中的事件处理
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- 在 C++/CLI 中将 .NET 事件从一个 DLL 引发到另一个 DLL
- 如何创建事件驱动的 SDL2 应用程序
- Windows 进程间同步类似事件?
- 如何从C++端挂接到 QML 项的 onClick 事件
- 如何通过多类"Union variable" (sfml) 使用轮询事件
- 如何在Qt 4.8中阻止/忽略/丢弃早于特定超时的用户输入事件
- C++ 信号和插槽不工作:插槽不响应事件
- 在虚幻引擎中触发C++ dll的事件
- 未触发OnTouchMove事件