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

Customizing touches in the sprite class

In this section, we will create a custom touch sprite class to show that touch functions can also be used to add to individual classes and not only to scene nodes. This will also let us move the objects that were previously added to the scene.

Getting ready

As we will need to create a custom class, we need to create a new class and call it SSCustomSprite.

How to do it…

First, we will add the following in the header file:

#import "CCSprite.h"
#import "cocos2d.h"

@interface SSCustomSprite :CCSprite

@end

Then, in the interface file, we will add the following:

#import "SSCustomSprite.h" @implementation SSCustomSprite - (void)onEnter { [superonEnter]; self.userInteractionEnabled = true; } - (void)onExit { [superonExit]; ...

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