0

私は cocos2D のゲームで xCode を使用していますが、解決すべき問題が 1 つあります。

基本的に、タッチイベントをキャプチャするカスタムクラスである SneakyButton を使用しているため、PNG ファイルまたは Circle Radius を使用して何かを行うことができます。私の場合は弾丸を発射します。

デバイスでプロジェクトを SD モード (1x スケール) で iOS (iPhone 4 以前の網膜の場合) で実行すると、すべて正常に実行されます。

ただし、デバイスで Retina ディスプレイ モード (2 倍スケール) でプロジェクトを実行すると、アプリのデリゲートでスケールを 2 倍に設定します。PNG が表示されます。タッチが表示されないことを除いて、すべて正常に動作します。

コードのこの部分に絞り込みました。

'
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (active) return NO;

    CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
    location = [self convertToNodeSpace:location];
        //Do a fast rect check before doing a circle hit check:
    if(location.x < -radius || location.x > radius || location.y < -radius || location.y > radius){
        return NO;
    }else{
        float dSq = location.x*location.x + location.y*location.y;
        if(radiusSq > dSq){
            active = YES;
            if (!isHoldable && !isToggleable){
                value = 1;
                [self schedule: @selector(limiter:) interval:rateLimit];
            }
            if (isHoldable) value = 1;
            if (isToggleable) value = !value;
            return YES;
        }
    }
return NO;
}
'
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (!active) return;

    CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
    location = [self convertToNodeSpace:location];
        //Do a fast rect check before doing a circle hit check:
    if(location.x < -radius || location.x > radius || location.y < -radius || location.y > radius){
        return;
    }else{
        float dSq = location.x*location.x + location.y*location.y;
        if(radiusSq > dSq){
            if (isHoldable) value = 1;
        }
        else {
            if (isHoldable) value = 0; active = NO;
        }
    }
}
'
- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    if (!active) return;
    if (isHoldable) value = 0;
    if (isHoldable||isToggleable) active = NO;
}

- (void)ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event
{
    [self ccTouchEnded:touch withEvent:event];
}

@end
'

私の問題はコードの半径部分にあると思います...誰かが以前にこれに遭遇したことがありますか、それを機能させるためにこのコードのどの部分を変更する必要があるかについてのアイデアはありますか? この 6 か月のプロジェクトが完了する前の最後のつまずきです。ヘルプ!よろしくお願いします!

4

1 に答える 1

0

半径をどこに設定していますか?またはどのように取得しますか?png ファイル自体から半径を取得する場合は、スケーリングが適用される前にスプライトの半径を指定する contentsize ではなく、radius の境界ボックスを使用していることを確認してください。

于 2011-06-10T09:54:34.157 に答える