Advertisement
Guest User

HelloWorldScene.m

a guest
Jun 27th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1.  
  2. #import "HelloWorldScene.h"
  3. #import "IntroScene.h"
  4. #import "CCAnimation.h"
  5.  
  6. // -----------------------------------------------------------------------
  7. #pragma mark - HelloWorldScene
  8. // -----------------------------------------------------------------------
  9.  
  10. @implementation HelloWorldScene
  11. {
  12.     CCSprite *daveStanding;
  13.     CCSprite *highway1;
  14.     CCSprite *cloud1;
  15.     CCSprite *daveRunSG;
  16. }
  17.  
  18. // -----------------------------------------------------------------------
  19. #pragma mark - Create & Destroy
  20. // -----------------------------------------------------------------------
  21.  
  22. + (HelloWorldScene *)scene
  23. {
  24.     return [[self alloc] init];
  25. }
  26.  
  27. // -----------------------------------------------------------------------
  28.  
  29. - (id)init
  30. {
  31.     // Apple recommend assigning self with supers return value
  32.     self = [super init];
  33.     if (!self) return(nil);
  34.    
  35.     CCNodeColor *bkg = [CCNodeColor nodeWithColor:[CCColor colorWithCcColor3b:ccc3(32, 56, 236)]];
  36.     [self addChild:bkg];
  37.    
  38.     // Adding Sprites
  39.    
  40.     daveStanding = [CCSprite spriteWithImageNamed:@"dave_standing.png"];
  41.     [daveStanding.texture setAntialiased:NO];
  42.     daveStanding.position = ccp(150,150);
  43.     [self addChild:daveStanding];
  44.    
  45.     highway1 = [CCSprite spriteWithImageNamed:@"highway_tileset.png"];
  46.     [highway1.texture setAntialiased:NO];
  47.     highway1.position = ccp(0,45);
  48.     [self addChild:highway1];
  49.    
  50.     cloud1 = [CCSprite spriteWithImageNamed:@"cloud.png"];
  51.     [cloud1.texture setAntialiased:NO];
  52.     cloud1.position = ccp(300,109.5);
  53.     [self addChild:cloud1];
  54.    
  55.     // Testing
  56.    
  57.     [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"dave_default.plist"];
  58.    
  59.     NSMutableArray *animFrames = [NSMutableArray array];
  60.     for(int i = 1; i <=4; ++i)
  61.     {
  62.         [animFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"char%d.png", i]]];
  63.     }
  64.     CCAnimation *anim = [CCAnimation animationWithSpriteFrames:animFrames delay:0.1f];
  65.    
  66.     // Add a sprite
  67.     daveRunSG = [CCSprite spriteWithImageNamed:@"1.png"];
  68.     daveRunSG.position = ccp(self.contentSize.width/2, self.contentSize.height/2);
  69.     CCActionAnimate *animAction = [CCActionAnimate actionWithAnimation:anim];
  70.     CCActionRepeatForever *animationRepeatFor = [CCActionRepeatForever actionWithAction:animAction];
  71.     [daveRunSG runAction:animationRepeatFor];
  72.     [self addChild:daveRunSG];
  73.    
  74.     // done
  75.     return self;
  76. }
  77.  
  78. -(void) update:(CCTime)delta
  79.     {
  80.     highway1.position = ccp(highway1.position.x +100*delta, highway1.position.y);
  81.     if (highway1.position.x > 480+128) {
  82.         highway1.position = ccp(-128, highway1.position.y);
  83.     }
  84. }
  85. // -----------------------------------------------------------------------
  86. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement