Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////
- // HelloWorldLayer.h
- // When you import this file, you import all the cocos2d classes
- #import "cocos2d.h"
- // HelloWorldLayer
- @interface HelloWorldLayer : CCLayer
- {
- CCLabelTTF *_label;
- }
- // returns a CCScene that contains the HelloWorldLayer as the only child
- +(CCScene *) scene;
- @end
- ////////////////////////////////////
- // HelloWorldLayer.m
- // Import the interfaces
- #import "HelloWorldLayer.h"
- // HelloWorldLayer implementation
- @implementation HelloWorldLayer
- +(CCScene *) scene
- {
- // 'scene' is an autorelease object.
- CCScene *scene = [CCScene node];
- // 'layer' is an autorelease object.
- HelloWorldLayer *layer = [HelloWorldLayer node];
- // add layer as a child to scene
- [scene addChild: layer];
- // return the scene
- return scene;
- }
- // on "init" you need to initialize your instance
- -(id) init
- {
- // always call "super" init
- // Apple recommends to re-assign "self" with the "super" return value
- if( (self=[super init])) {
- // create and initialize a Label
- _label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
- // ask director the the window size
- CGSize size = [[CCDirector sharedDirector] winSize];
- // position the label on the center of the screen
- _label.position = ccp( size.width /2 , size.height/2 );
- // add the label as a child to this Layer
- [self addChild: _label];
- self.isTouchEnabled = YES;
- }
- return self;
- }
- // on "dealloc" you need to release all your retained objects
- - (void) dealloc
- {
- // in case you have something to dealloc, do it in this method
- // in this particular example nothing needs to be released.
- // cocos2d will automatically release all the children (Label)
- // don't forget to call "super dealloc"
- [super dealloc];
- }
- -(void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
- {
- UITouch *touch = [touches anyObject];
- CGPoint location = [touch locationInView:[touch view]];
- location = [[CCDirector sharedDirector] convertToGL:location];
- [_label runAction:[CCMoveTo actionWithDuration:3 position:location]];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement