O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a custom sprite class

We just considered how to add a sprite to a scene; however, in the future, you may want a separate sprite class so that you can add your own behaviors to the class. In this section, we will discuss how to create our own custom sprite class by extending the base CCSprite class.

Getting ready

Let's take a look at how to create a custom sprite class so that it can have its own movement and update the function later.

For this, we will have to create new files.

  1. Go to File | New | File. Under iOS | Source, select Cocoa Touch Class. Click on Next.
    Getting ready
  2. Next, we will give it a class name. We will select CCSprite as Subclass of and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required