Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to slice/cut sprites in iOS (Core Graphics)
    primarykey
    data
    text
    <p>I am working on a game and I would like to add a proper slicing feature in it.. so when a sprite sliced, 2 new sprites should be created.. please check <a href="http://cdn1.raywenderlich.com/wp-content/uploads/2012/05/ccc_cutdiagram.png" rel="nofollow noreferrer">here</a></p> <p>At the moment, I am just reducing the size and duplicating the sprites.. Something like this.. Thanks in advance.. </p> <pre><code> - (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 &lt; [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; } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload