Frage

If I need to add or subtract two shapes together and animate it as a whole entity, what is the easiest way to do it? For example if I subtract a smaller circle from a bigger circle, i get a donut.

If I then need to animate this entity and also animate many of this type of entities (donuts or whatever) will it be heavy on an iPad?

I need a direction to look into.

Thanks!

War es hilfreich?

Lösung

Your post is marked with the keyword "Core-Graphics," so I assume that's what you want to use. To add shapes, you simply draw the 2 or more shapes you want together. I recommend following a pattern of saving the graphics state, drawing your connected shapes, and the restore the graphics state for drawing the next set of shapes. Like this:

// Save the state
CGContextSaveGState (ctx);
// Do your drawing
CGContextBeginPath (ctx);
CGContextAddRect (ctx, rect);
CGContextAddEllipseInRect (ctx, ellipseRect); // Or whatever
CGContextClosePath (ctx);
CGContextFillPath (ctx);
// Restore the state
CGContextRestoreGState (ctx);

To subtract shapes, you can use a clipping path:

// This is the path you want to draw within
CGContextBeginPath (ctx);
CGContextAddRect (ctx);
CGContextClosePath (ctx);
CGContextClip (ctx);
// Now draw the shape you want constrained within the above path
CGContextBeginPath (ctx);
CGContextAddEllipseInRect (ctx, ellipseRect);
CGContextClosePath (ctx);
CGContextFillPath (ctx); // This will fill everything in the path that is also within the clipping path, and nothing that is outside of the clipping path

See also CGContextEOClip() for other ways to clip shapes.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top