Display SVG images on iOS using Cocos2D
Objective-C
Permalink
Failed to load latest commit information.
CCSVG.xcodeproj Updated linking, scheme and build settings. Sep 12, 2012
CCSVG.xcworkspace
example Updated readme. Jun 1, 2012
external Updated with new MonkVG include path. Jun 1, 2012
src
.gitmodules
LICENCE Added a licence and readme. May 29, 2012
README.md Updated readme. Jun 1, 2012

README.md

CCSVG - Display SVG images on iOS using Cocos2D

Overview

CCSVG provides an API for loading, displaying and animating SVG images on iOS using Cocos2D.

// load an svg image
CCSVGSource *source;
source = [CCSVGSource sourceWithFile:@"player_idle.svg"];

// display an svg image
CCSVGSprite *sprite;
sprite = [CCSVGSprite spriteWithSource:source];
sprite.position = ccp(240,160);

// create an svg animation
CCSVGAnimation *animation;
animation = [CCSVGAnimation animationWithSourcesNamed:@"player_walk_%04d.svg" 
                                                count:2 
                                                delay:1.0/15.0];

// run the animation on the sprite
CCSVGAnimate *animate;
animate = [CCSVGAnimate actionWithSVGAnimation:animation];
[sprite runAction:[CCRepeatForever actionWithAction:animate]]; 

Benefits

SVG images are displayed as vector data, not textures. Each file is tesselated and cached in a vertex buffer object, so the peformance penalty of tesselating and uploading the geometry to OpenGL only happens once when the file is first loaded.

  • Resolution-independence.
  • Smaller file size.
  • Smaller memory footprint.
  • Faster load times.

Drawbacks

There is a significant performance penalty for using images with transparent fills or strokes (drawing them properly means turning on blending in OpenGL). Avoid them where possible.

  • Incomplete SVG support (see what is implemented in MonkVG).
  • Antialiasing requires multisampling to be enabled, which has a performance penalty.

Installation

git clone git@github.com:lukelutman/CCSVG.git
git submodule init
git submodule update

Dependencies

Resources