0

Android 用の cocos2d-x でゲームを開発していますが、問題が発生しました。

    _hammer = CCSprite::createWithSpriteFrameName("Hammer.png");
    _hammer->setPosition(ccp(_screenSize.width * 0.5f - 4*((_hammer->getContentSize().width) * 0.15f), _screenSize.height * 0.055f ));
    _hammer->setVisible(true);
    _hammer->setScale((_screenSize.width / _hammer->getContentSize().width) * 0.15f);
    _hammer->setScale((_screenSize.height / _hammer->getContentSize().height) * 0.15f);
    _hammerSelected = true;


 {
    CCTouch *touch = (CCTouch *) pTouches->anyObject();
    CCPoint location = touch->locationInView();
    location = CCDirector::sharedDirector()->convertToGL(location);
    if ((CCRect::CCRectContainsPoint(_hammer->boundingBox(), location))) {
    //do something
    }

CC_SPRITE_DEBUG_DRAW と CC_SPRITEBATCHNODE_DEBUG_DRAW をオンにしましたが、問題は、boundingBox が見た目よりも大きいことです。境界ボックスの近くのどこかをクリックすると、実際に内部をクリックしたかのように登録されます。

誰でも私を助けることができますか?:)

4

2 に答える 2

0

これを試して:

 CCRect rect= _hammer->boundingBox();

 //multiply the scale value.
 rect.size.height*= _hammer->getScaleX();
 rect.size.width*= _hammer->getScaleY();

 if ((CCRect::CCRectContainsPoint(rect, location))) {
 //do something
 }
于 2014-04-04T13:23:16.130 に答える