Game Development Reference
In-Depth Information
layer if you need a group of objects to perform the same actions and behaviors. Moving
all objects to scroll them is one such case; sometimes you might want to rotate them or
reorder them so they're drawn on top of other objects. If all these objects are children of
a layer, you can simply change the layer's properties or run an action on the layer to af-
fect all its child nodes.
Note Many recommend not using too many CCLayer objects per scene. This
advice is often misunderstood. You can use as many layers as you want without
affecting performance any more than using any other node. However, things
change if the layer also accepts input, because touch or accelerometer events
are costly tasks. Don't use several layers receiving touch or accelerometer input
at the same time—one will do. Preferably one layer receives and handles input
and, where necessary, informs other nodes or classes about the input events by
forwarding them to registered objects. You usually do this via the per-
formSelector method that calls a method with a defined method signature.
See cocos2d's CCScheduler class for an example implementation.
Receiving Touch Events
The CCLayer class is designed to receive touch input, but only if you explicitly en-
able it. To enable receiving touch events, set the property isTouchEnabled to YES :
self.isTouchEnabled = YES;
This is best done in the class's init method, but you can change it at any time.
Once the isTouchEnabled property is set, a variety of methods for receiving touch
input will start to get called. These are the events received when a new touch begins,
when a finger is moved on the touchscreen, and when the user lifts the finger off the
screen. Canceled touches are rare, and you can safely ignore this method for the most
part or simply forward it to the ccTouchesEnded method.
▪ This is called when a finger just begins touching the screen:
withEvent:(UIEvent *)event
Search Nedrilad ::

Custom Search