【问题标题】:Swiping across multiple CCLayers在多个 CCLayer 上滑动
【发布时间】:2013-12-26 17:45:32
【问题描述】:

想象一个CCLayer 子类Block 的三个实例彼此相邻。每个都是 100x100 像素,并有一些基本的方形背景艺术。这三个对象是封装CCLayer 子类Container 的一部分。

如何在三个 Block 之间滑动并检测 Container 中每个 Block 的滑动/点击/触摸?

如果问题仅限于在Container 中处理Blocks 上的点击,那么可以使用委托。像BlockDelegate 这样的方法需要userTappedBlock:(Block *) b,只要点击Block,就会通知Container

但是,这种方法还不能用于刷卡。我在Container 中收到回调,但仅限于第一个被点击的Block

【问题讨论】:

    标签: delegates cocos2d-iphone gestures cclayer


    【解决方案1】:

    您可以在包含您的块的层中处理触摸。然后,在touchEnded:WithEvent: 方法中检查哪个块包含触摸的位置。

    【讨论】:

    • 类似的东西会起作用。虽然我想我会检查touchMovedtouchEnded,因为我正在浏览各个图层。无论如何,我只是认为块为我做触摸检测会很好。
    • 不要认为它是必要的。例如,看看 CCMenu 是如何实现的。所有的触摸都处理菜单,而不是项目。
    【解决方案2】:

    在CustomLayer.cpp中写这个方法来敲击图层

    void CustomLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)

    {

         CCTouch *touch = (CCTouch *) pTouches->anyObject();
         CCPoint location = touch->getLocationInView();
         location = CCDirector::sharedDirector()->convertToGL(location);
    
             if(layer->boundingBox().containsPoint(location))
                    CCLog("layer Hit Test");
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多