0

現時点では、ccTouchesBegan && ccTouchesMoved メソッドを使用していくつかのオブジェクトを移動できるパズル ゲームがあります。

ccTouchesBegan で呼び出されます:

if (CGRectContainsPoint(newBoundingBox, touchLocation))
    {
        //Set the selectedSprite to the sprite with newBoundingBox
    }

次に、ccTouchesMoved で次のことを行います。

CGPoint translation = ccpSub(touchLocation, oldTouchLocation);
newPos = ccpAdd(selSprite.position, translation);
selectedSprite.position = newPos;

これですべて問題なくうまく動作しますが、移動しているオブジェクトの一部は約 140x40px (320x480 iPhone 上) であり、ccTouchesBegan メソッドが touchLocation を含む boundingBox を認識しないことがあります。

私の質問は、オブジェクトのboundingBoxのサイズを大きくして、ユーザーが少し触れて「ミス」した場合に役立つようにすることはできますか? タッチスクリーンで障害物を動かすのに非常に正確である必要があるのは少しイライラします.

編集:iPhoneの場合:

touchLocation を取得する方法、これは ccTouchesBegan にあります。

NSSet *touchSet = [event allTouches];
int numberOfTouches = [touchSet count];
CGPoint touchLocation = [self convertTouchToNodeSpace:[touches anyObject]];

allTouches は、タッチが始まると自動的に渡されます。

4

1 に答える 1

0
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [self convertTouchToNodeSpace: touch];

    for (CCSprite *tempSprite in sprites )
    {
                //Increase the size of bounding box..
        CGRect rect=tempSprite.boundingBox;
                rect.size.height=rect.size.height + 20;
                rect.size.width=rect.size.width + 20;
        if (CGRectContainsPoint(rect, location))
        {
                   //Your stuffs
        }
    }
}
于 2013-04-07T04:51:32.430 に答える