4

私はゲームに取り組んでおり、適切なスライス機能をゲームに追加したいと考えています..スプライトがスライスされると、2つの新しいスプライトが作成されるはずです..こちらを確認してください

現時点では、サイズを縮小してスプライトを複製しています..このようなもの..よろしくお願いします..

 - (BOOL) sliceSprite: (Sprite *) sprite withPath: (UIBezierPath *) slicePath


 {

            CGSize size = sprite.size;
            size.width /= 2; 
            size.height /=2;
            sprite.size = size;
            sprite.sliced = YES;

            Sprite *newSprite = [[Sprite alloc] initWithImage: sprite.image];

            newSprite.position = sprite.position;
            newSprite.size = size;
            newSprite.sliced = YES;
            newSprite.inView = YES;
            newSprite.xVelocity = SLICE_SPEEDUP * sprite.yVelocity;
            newSprite.yVelocity = SLICE_SPEEDUP * sprite.xVelocity;
            newSprite.angularVelocity = -SLICE_REVUP * sprite.angularVelocity;

            [sprites addObject: newSprite];
            [newSprite release];

        sprite.angularVelocity = SLICE_REVUP * sprite.angularVelocity;
            sprite.xVelocity = -SLICE_SPEEDUP * sprite.xVelocity;
            sprite.yVelocity = -SLICE_SPEEDUP * sprite.yVelocity;

            return YES;
    }

- (void) sliceSpritesInSwipePath
{
    CGRect swipeRect = [swipePath bounds];


        for (NSUInteger i = 0; i < [sprites count]; i++)
        {
                Sprite *sprite = [sprites objectAtIndex: i];

                if ([sprite intersectsWithPathInArray: swipePoints
                                               inRect: swipeRect])
                        if ([self sliceSprite: sprite withPath: swipePath])
                        {

                                [self resetSwipe];

                                if (![sliceSound isPlaying])
                                        [sliceSound play];

                break;
                        }
        }

}

4

2 に答える 2

1

分割の特定の行は必要ですか? Fruit Ninja は、果物を 2 つの半分に分割するだけです。これは非常に簡単に行うことができます。

  • 元のスプライトの半分の幅のスプライトを 2 つ作成する
  • 元のスプライトの水平方向の中心線に沿って 1/4 と 3/4 の位置に配置します。
  • 回転・加速などを加える
  • 左のスプライトにテクスチャの左半分が含まれ、右のスプライトにテクスチャの右半分が含まれるように、テクスチャ座標を変更します。
于 2012-09-08T18:20:10.230 に答える
0

ここでは CoreGraphics を使用しているため、スプライトを描画するときに単純にクリッピング パスを使用してみませんか?

スライスするスプライトを複製し、それぞれのクリッピング パスとして 2 つの半分をマスクする単純なポリゴンを適用します。必要な関数が呼び出されCGContextClip、短いチュートリアルがここにあります。

編集:チュートリアルには、この例がリストされています:

CGContextBeginPath (context);
CGContextAddArc (context, w/2, h/2, ((w>h) ? h : w)/2, 0, 2*PI, 0);
CGContextClosePath (context);
CGContextClip (context);

これにより、現在のパスが円に設定され、現在のパスがクリッピング領域として適用されます。

于 2012-09-10T15:47:53.530 に答える