Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  InfiniteOffsetNode.m
  3. //  133kcaves2013
  4. //
  5. //  Created by Jason McCarrell on 2013-11-15.
  6. //  Copyright (c) 2013 Jason McCarrell. All rights reserved.
  7. //
  8.  
  9. #import "InfiniteOffsetScene.h"
  10.  
  11. @implementation InfiniteOffsetScene
  12.  
  13. //TODO: centerNode isn't initiated or anything, that is bad... figure out a better inti or something.
  14. //TODO: ugh, also ive lost control of the y... need a better solution.
  15. -(id)initWithSize:(CGSize)size {
  16.     if (self = [super initWithSize:size]) {
  17.         self.centerNodeOffset = CGPointZero;
  18.        
  19.         self.gameNode = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size: CGSizeMake(size.width, size.height)];
  20.         self.gameNode.anchorPoint = CGPointZero;
  21.         self.gameNode.position = CGPointZero;
  22.         self.centerNodeOffset = CGPointMake(20.0, 0.0); //TODO: CHEATING!!!!! it's the ships starting x
  23.         [self addChild:self.gameNode];
  24.     }
  25.     return self;
  26. }
  27.  
  28. -(void)update:(CFTimeInterval)currentTime {
  29.     [self.gameNode.children enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL* stop) {
  30.         SKNode* node = object;
  31.         node.position = CGPointMake(node.position.x + self.centerNodeOffset.x - 20.0, node.position.y);
  32.     }];
  33. }
  34.  
  35. -(void)didSimulatePhysics
  36. {
  37.     NSLog(@"Offset-x: %f", self.centerNodeOffset.x);
  38.     self.centerNodeOffset = self.centerNode.position;
  39.     [self.gameNode.children enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL* stop) {
  40.         SKNode* node = object;
  41.         node.position = CGPointMake(node.position.x - self.centerNodeOffset.x + 20.0, node.position.y);
  42.     }];
  43. }
  44.  
  45. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement