Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "HelloWorldScene.h"
- #import "IntroScene.h"
- #import "CCAnimation.h"
- // -----------------------------------------------------------------------
- #pragma mark - HelloWorldScene
- // -----------------------------------------------------------------------
- @implementation HelloWorldScene
- {
- CCSprite *daveStanding;
- CCSprite *highway1;
- CCSprite *cloud1;
- CCSprite *daveRunSG;
- }
- // -----------------------------------------------------------------------
- #pragma mark - Create & Destroy
- // -----------------------------------------------------------------------
- + (HelloWorldScene *)scene
- {
- return [[self alloc] init];
- }
- // -----------------------------------------------------------------------
- - (id)init
- {
- // Apple recommend assigning self with supers return value
- self = [super init];
- if (!self) return(nil);
- CCNodeColor *bkg = [CCNodeColor nodeWithColor:[CCColor colorWithCcColor3b:ccc3(32, 56, 236)]];
- [self addChild:bkg];
- // Adding Sprites
- daveStanding = [CCSprite spriteWithImageNamed:@"dave_standing.png"];
- [daveStanding.texture setAntialiased:NO];
- daveStanding.position = ccp(150,150);
- [self addChild:daveStanding];
- highway1 = [CCSprite spriteWithImageNamed:@"highway_tileset.png"];
- [highway1.texture setAntialiased:NO];
- highway1.position = ccp(0,45);
- [self addChild:highway1];
- cloud1 = [CCSprite spriteWithImageNamed:@"cloud.png"];
- [cloud1.texture setAntialiased:NO];
- cloud1.position = ccp(300,109.5);
- [self addChild:cloud1];
- // Testing
- [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"dave_default.plist"];
- NSMutableArray *animFrames = [NSMutableArray array];
- for(int i = 1; i <=4; ++i)
- {
- [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"char%d.png", i]]];
- }
- CCAnimation *anim = [CCAnimation animationWithSpriteFrames:animFrames delay:0.1f];
- // Add a sprite
- daveRunSG = [CCSprite spriteWithImageNamed:@"1.png"];
- daveRunSG.position = ccp(self.contentSize.width/2, self.contentSize.height/2);
- CCActionAnimate *animAction = [CCActionAnimate actionWithAnimation:anim];
- CCActionRepeatForever *animationRepeatFor = [CCActionRepeatForever actionWithAction:animAction];
- [daveRunSG runAction:animationRepeatFor];
- [self addChild:daveRunSG];
- // done
- return self;
- }
- -(void) update:(CCTime)delta
- {
- highway1.position = ccp(highway1.position.x +100*delta, highway1.position.y);
- if (highway1.position.x > 480+128) {
- highway1.position = ccp(-128, highway1.position.y);
- }
- }
- // -----------------------------------------------------------------------
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement