I'm using Sprite Kit Xcode 6 and I need to add a sprite and it won't appear when I try to add it... I created a Cocoa Touch Class and The files are below..
level1Layout.m
#import "level1Layout.h" #import "GameScene.h" @implementation level1Layout SKSpriteNode *testEnemy; -(void) addSprite{ NSLog(@"FFFFFFF"); [self addChild:testEnemy]; } -(void) testMethod{ NSLog(@"adad"); testEnemy = [SKSpriteNode spriteNodeWithImageNamed:@"TestEnemy"]; testEnemy.position = CGPointMake(512, 384); NSLog(@"%f", testEnemy.position.x); NSLog(@"%f", testEnemy.position.y); [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(addSprite) userInfo:nil repeats:NO]; } -(void) runAddLevel1Layout{ [[GameScene new] runLevel1Layout]; } @end
(I used the NSLogs to make sure it was being called)
level1Layout.h
#import <SpriteKit/SpriteKit.h> #import <Foundation/Foundation.h> #import "GameScene.h" @interface level1Layout : SKScene -(void) testMethod; -(void) runAddLevel1Layout; -(void) addSprite; @end
And the main class where it starts, if someone wants me to put it in, just let me know.
GameScene.m
#import "GameScene.h" #import "level1Layout.h" @implementation GameScene SKSpriteNode *trans; SKSpriteNode *level1ButtonRed; -(void)didMoveToView:(SKView *)view { /* Setup your scene here */ level1ButtonRed = [SKSpriteNode spriteNodeWithImageNamed:@"levelButtonRed"]; } -(void) runLevel1Layout{ [[level1Layout new] testMethod]; } +(void) addLevel1Layout{ } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ for (UITouch *touch in touches) { CGPoint location = [touch locationInNode:self]; trans.position = location; [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(runLevel1Layout) userInfo:nil repeats:NO]; } } -(void)update:(CFTimeInterval)currentTime { /* Called before each frame is rendered */ } @end
Anyone know?