iOS Can't find interface declaration

cpuin

macrumors member
Original poster
Feb 3, 2013
76
0
I'm trying to subclass my custom class. I simply add more functionality of SKScene class MyClass and than i want to create more instances of it like Scene0001, Scene0002 etc.

What i got is the error:Can't find interface declaration for MyScene in superclass of Scene0001

i import MyScene.h in Scene0001.h

and in other class i use this:

Scene0001 *start = [[Scene0001 alloc] initWithSize:self.size];
 

cpuin

macrumors member
Original poster
Feb 3, 2013
76
0
MyScene.h

Code:
#import <SpriteKit/SpriteKit.h>
#import "DSMultilineLabelNode.h"
#import "MenuScene.h"


@interface MyScene : SKScene

@property (nonatomic, strong) SKSpriteNode *selectedNode;

@end


MyScene.m

Code:
#import "MyScene.h"

@implementation MyScene
{
    SKSpriteNode *_rect;
}

-(id)initWithSize:(CGSize)size{
    if (self = [super initWithSize:size]) {
        /* Setup your scene here */
        
        
        //Set background image.
        SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"bg_military@2x.gif"];
        background.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
        background.xScale = 0.5;
        background.yScale = 0.5;
        [self addChild:background];
        
        //button manu button
        SKSpriteNode *menu_back_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_back_button@2x.png"];
        menu_back_button.position = CGPointMake(CGRectGetMidX(self.frame)-130, CGRectGetMidY(self.frame)-268);
        menu_back_button.xScale = 0.5;
        menu_back_button.yScale = 0.5;
        [self addChild:menu_back_button];
        
        //button manu button
        SKSpriteNode *menu_home_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_home_button@2x.png"];
        menu_home_button.position = CGPointMake(CGRectGetMidX(self.frame)-65, CGRectGetMidY(self.frame)-268);
        menu_home_button.name = @"home";
        menu_home_button.xScale = 0.5;
        menu_home_button.yScale = 0.5;
        [self addChild:menu_home_button];
        
        //button manu button
        SKSpriteNode *menu_man_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_man_button@2x.png"];
        menu_man_button.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-268);
        menu_man_button.xScale = 0.5;
        menu_man_button.yScale = 0.5;
        [self addChild:menu_man_button];
        
        //button manu button
        SKSpriteNode *menu_note_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_note_button@2x.png"];
        menu_note_button.position = CGPointMake(CGRectGetMidX(self.frame)+65, CGRectGetMidY(self.frame)-268);
        menu_note_button.xScale = 0.5;
        menu_note_button.yScale = 0.5;
        [self addChild:menu_note_button];
        
        
        //button manu button
        SKSpriteNode *menu_settings_button = [SKSpriteNode spriteNodeWithImageNamed:@"menu_settings_button@2x.png"];
        menu_settings_button.position = CGPointMake(CGRectGetMidX(self.frame)+130, CGRectGetMidY(self.frame)-268);
        menu_settings_button.name = @"settings";
        menu_settings_button.xScale = 0.5;
        menu_settings_button.yScale = 0.5;
        [self addChild:menu_settings_button];
        
        
        
        
    }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint positionInScene = [touch locationInNode:self];
    [self selectNodeForTouch:positionInScene];
}


- (void)selectNodeForTouch:(CGPoint)touchLocation {
    //1
    SKSpriteNode *touchedNode = (SKSpriteNode *)[self nodeAtPoint:touchLocation];
    
    //2
	if(![_selectedNode isEqual:touchedNode]) {
		[_selectedNode removeAllActions];
		[_selectedNode runAction:[SKAction rotateToAngle:0.0f duration:0.1]];
        
		_selectedNode = touchedNode;
        
        //1
		if([[touchedNode name] isEqualToString:@"home"]) {
			
            
            MenuScene *start = [[MenuScene alloc] initWithSize:self.size];
            SKTransition *reveal = [SKTransition fadeWithColor:[UIColor clearColor] duration:1];
            [self.scene.view presentScene: start transition: reveal];
            
            [self runAction:[SKAction playSoundFileNamed:@"button_select.mp3" waitForCompletion:NO]];
            
		}
        
        if([[touchedNode name] isEqualToString:@"settings"]) {
			
            
            //rect
            _rect = [SKSpriteNode spriteNodeWithImageNamed:@"rectangle@2x.png"];
            _rect.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
            _rect.name = @"rect";
            _rect.xScale = 0.5;
            _rect.yScale = 0.5;
            [self addChild:_rect];
            
            SKLabelNode *text = [[SKLabelNode alloc] initWithFontNamed:@"Times New Roman"];
            text.position = CGPointMake(_rect.xScale+195, _rect.yScale+205);
            text.name = @"close";
            text.text = @"close";
            
            [_rect addChild:text];
            
		}
        
        if([[touchedNode name] isEqualToString:@"close"]) {
			
            
            [_rect removeFromParent];
            
            
		}
        
        //2
		
        
        
	}
    
}

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
}

@end

Scene0001.h


Code:
#import <SpriteKit/SpriteKit.h>
#import "MyScene.h"

@interface Scene0001 : MyScene

@end

Scene0001.m


Code:
#import "Scene0001.h"


@implementation Scene0001

@end
 

ianray

macrumors 6502
Jun 22, 2010
452
0
@
Code:
Scene0001 *start = [[Scene0001 alloc] initWithSize:self.size];
(Note the posted code does not contain the quoted line.)

The error message: cannot find interface declaration for 'Foo', superclass of 'Bar' means what it says: that the compiler cannot see an @interface definition for Foo. Or, in other words, the relevant header file has not been #import'ed.
 

cpuin

macrumors member
Original poster
Feb 3, 2013
76
0
(Note the posted code does not contain the quoted line.)

The error message: cannot find interface declaration for 'Foo', superclass of 'Bar' means what it says: that the compiler cannot see an @interface definition for Foo. Or, in other words, the relevant header file has not been #import'ed.
Yes, i know what the error means, but i have imported the class in the header as you can see
 

ianray

macrumors 6502
Jun 22, 2010
452
0
@
and in other class i use this:
Code:
Scene0001 *start = [[Scene0001 alloc] initWithSize:self.size];
Where is that line of code? Do you import the header file?