No visible #interface error using enumerateChildNodesWithName? - ios

I have ran this project in the past without errors and all the sudden, red flags go up when I try to use:
-(void)aimRocketLauncher:(CGPoint)location
{
__block CGPoint handleLocation;
[self enumerateChildNodesWithName:#"handle" usingBlock: ^(SKNode *node, BOOL *stop) {
SKSpriteNode *handle = (SKSpriteNode *) node;
handle.name = #"handle";
if(CGRectContainsPoint(handle.frame, location)) {
handle.position = location;
handleLocation = location;
}
}];
[self enumerateChildNodesWithName:#"rocketLauncher" usingBlock: ^(SKNode *node, BOOL *stop) {
SKSpriteNode *rocketLauncher = (SKSpriteNode *) node;
CGPoint launcherPosition = rocketLauncher.position;
CGFloat slope = (handleLocation.y - launcherPosition.y) / (handleLocation.x - launcherPosition.x);
//NSLog(#"%f", slope);
CGFloat angle = tan(slope);
angle *= angle;
SKAction *rotate = [SKAction rotateToAngle:degToRad(angle + 90) duration:0.05];
// if (angle < 270 && angle < 180) {
// [rocketLauncher removeAllActions];
// [rocketLauncher runAction:rotate];
//
// }
}];
}
Not just this one, but all over the project. I tried undoing and cleaning the project.
The exact error:
ARC Semantic Issue No visible #interface for 'GameScene' declares the selector 'enumerateChildNodesWithName:usingBlock:'
It really doesn't matter what the rest of the code is because I know this works. When I start to type [self the autocomplete finds it and when I right click on enumerateChildNodesWithName then Jump to Definition, it's there. This means that the Sprite Kit is imported correctly. I tried closing out the project and restarting the Mac, still nothing happened.
I tried using this code in another class to see what would happen. Same error.
The only difference I see in the 2 different projects that have this similar code is that one was started in Xcode 5 and this one Xcode 6.
I also do not want to use any sks file whatsoever.
.h
#import <SpriteKit/SpriteKit.h>
#import "Settings.h"
#import "TopHud.h"
#import "Hud.h"
#import "Menu.h"
#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
#class Menu;
#class Settings;
#class TopHud;
#class Hud;
#interface GameScene : SKScene
{
}
#end
Top of the .m file
#import "GameScene.h"
#implementation GameScene
I really need to work out this problem because it's killing my entire project that is fairly large. I'm working on it alone.

I changed the Deployment Target from 8 to 7.1

Related

Using SPUserResizableView in Swift

I'm trying to use the SPUserResizableView created by Spoletto in github (https://github.com/spoletto/SPUserResizableView).
I imported the .h and .m files, created a bridge and added the delegates to my controller.
I think problem is that problem is that the library is very old and that's why I get many errors in the .h and .m files so I can't use the library.
Errors - http://postimg.org/gallery/3bq2ldo0m/
Can you help me setup the library in swift?
I also got the same error, Just add these two in SPUserResizableView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
Your problem will be resolved.
You need to set up an Objective-C bridging header and then import it in there. To do this:
Drag and drop the .h and .m SPUserResizableView files into your project.
When Xcode asks if you want to create a bridging header, select 'Yes'.
Type in the new file called 'YOUR-PROJECT-NAME-bridging-header.h' this code:
#import SPUserResizableView.h
You should now be able to use it in Swift!
I got this working with Swift 4 by moving the variable declarations from the interface to the implementation, and removing the release and dealloc code.
SPUserResizableView.h changed to
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
typedef struct SPUserResizableViewAnchorPoint {
CGFloat adjustsX;
CGFloat adjustsY;
CGFloat adjustsH;
CGFloat adjustsW;
} SPUserResizableViewAnchorPoint;
#protocol SPUserResizableViewDelegate;
#class SPGripViewBorderView;
#interface SPUserResizableView : UIView {
}
//...
//(identical from this point on)
SPUserResizableView.m changed to
//...
//(identical up to)
//CGColorSpaceRelease(baseSpace), baseSpace = NULL;
CGColorSpaceRelease(baseSpace);
baseSpace = NULL;
#implementation SPUserResizableView
SPGripViewBorderView *borderView;
UIView *contentView;
CGPoint touchStart;
CGFloat minWidth;
CGFloat minHeight;
// Used to determine which components of the bounds we'll be modifying, based upon where the user's touch started.
SPUserResizableViewAnchorPoint anchorPoint;
id <SPUserResizableViewDelegate> delegate;
//#synthesize contentView, minWidth, minHeight, preventsPositionOutsideSuperview, delegate;
//...
//(this part identical)
- (void)dealloc {
[contentView removeFromSuperview];
}
#end

Presenting a SKSpritenode from different class ("addChild")

I have a Class for my Sprite and I'm trying to addChild from that class. The problem is it renders it and doesn't crash - I just can't see the image. I know the images position is right because created and added the child from the gameScene class and it worked and loaded.
I'm thinking this isn't working because its not subclass of SKscene that's why I added the main node from gameScene but didn't solve the problem.
I set up a "mainNode" node
keys is just the name of the sprite and its the class name
I know the image is being rendered its just not visible for some reason.
I know this because if I add no image name not "key_green" and change it to nothing. I get an console msg saying it can't find that image.
gameScene.m
#import "GameScene.h"
#import "Keys.h"
#implementation GameScene
#synthesize mainNode;
-(void)didMoveToView:(SKView *)view {
self.backgroundColor = [UIColor whiteColor];
mainNode = [SKNode node];
[self addChild:mainNode];
Keys * KeysOBJ =[[Keys alloc] init];
[KeysOBJ initKeys];
}
keys.h
#import <SpriteKit/SpriteKit.h>
#import "GameScene.h"
#interface Keys : SKSpriteNode{
SKSpriteNode * key1;
}
#property SKNode* mainNode;
-(void)initKeys;
-(void)loadKeys;
keys.m
#import "Keys.h"
#import "GameScene.h"
#implementation Keys{
}
#synthesize mainNode;
-(void)initKeys{
key1 = [SKSpriteNode spriteNodeWithImageNamed:#"key_red"];
key1.position = CGPointMake((self.frame.size.width)- (self.frame.size.width)+350, (self.frame.size.height)-(self.frame.size.height)+50);
[mainNode addChild:key1];
}
Your mainNode is nil in your Keys because you never set it before you call initKeys. This in theory will get it working.
Keys * KeysOBJ =[[Keys alloc] init];
KeysOBJ.mainNode = mainNode;
[KeysOBJ initKeys];
Also consider this
key1.position = CGPointMake((self.frame.size.width)- (self.frame.size.width)+350, (self.frame.size.height)-(self.frame.size.height)+50);
self doesn't have a size because you just called init and never supplied a texture or a size. Meaning your sprite location will likely be 350,50.
With that being said you are over complicating it. Your Keys shouldn't be a subclass of SKSpriteNode if you are never going to set a texture to it. It should be a SKNode.
Hopefully that makes some sense and gets you pointed back in the right direction.

Accessing variables from another class when importing a .ccbi file

I know this topic is covered in a hundred posts here, but I'm having a lot of trouble with this particular instance and cannot figure it out.
Basically, I'm using Spritebuilder to import sprites/nodes into my game. I import a sprite of some specific class in the body of the GameScene class, but I want to be able to define a variable inside of my sprite class, and then edit it from the GameScene class. For example, if my sprite collects a coin inside the GameScene, I want to change the speed of my sprite inside of the update method in the sprite class.
Below is my code, but unfortunately it isn't working. The variable increaseY and increaseX do not appear to be available in my GameScene class. I know this is because I didn't instantiate the Penguin class properly, but I don't know how to properly create an instance of this class while simultaneously importing the .ccbi file of it. The problem line is commented on and has a bunch of ** next to it to easily find it. It's in GameScene.m. I really appreciate the help, been stuck on this for several hours.
Penguin.h
#import "CCSprite.h"
#interface Penguin : CCSprite
{
float xPosition;
float yPosition;
}
#property (nonatomic,assign) float increaseY;
#property (nonatomic,assign) float increaseX;
#end
Penguin.m
#import "Penguin.h"
#implementation Penguin
#synthesize increaseX;
#synthesize increaseY;
- (id)init {
self = [super init];
if (self) {
CCLOG(#"Penguin created");
}
return self;
}
-(void) update:(CCTime)delta
{
self.position = ccp(self.position.x + increaseX,self.position.y + increaseY);
}
#end
GameScene.h
#import "CCNode.h"
#interface GameScene : CCNode
#end
GameScene.m
#import "GameScene.h"
#import "Penguin.h"
#implementation GameScene
{
CCPhysicsNode *_physicsNode;
CCNode *_catapultArm;
CCNode *_levelNode;
CCNode *_contentNode;
}
// is called when CCB file has completed loading
- (void)didLoadFromCCB {
self.userInteractionEnabled = TRUE;
CCScene *level = [CCBReader loadAsScene:#"Levels/Level1"];
[_levelNode addChild:level];
}
// called on every touch in this scene
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
[self launchPenguin];
}
- (void)launchPenguin {
// loads the Penguin.ccb we have set up in Spritebuilder
CCNode* penguin = [CCBReader load:#"Penguin"];
penguin.position = ccpAdd(_catapultArm.position, ccp(16, 50));
[_physicsNode addChild:penguin];
//THE FOLLOWING LINE DOES NOT WORK********************************
penguin.increaseY = 1;
// Gives Error------Property "increaseX" not found on object of type "CCNode *"
self.position = ccp(0, 0);
CCActionFollow *follow = [CCActionFollow actionWithTarget:penguin worldBoundary:self.boundingBox];
[_contentNode runAction:follow];
}
You have to change this line:
CCNode* penguin = [CCBReader load:#"Penguin"];
To this line:
Penguin* penguin = (Penguin*)[CCBReader load:#"Penguin"];
In the old line you were using the compiler was giving you an error because the CCNode class does not have a property called increaseX. increaseX is part of the Penguin class. If you want to access properties of the Penguin class you need to use a cast and let the compiler know, that what you are loading using the CCBReader is actually a Penguin instance.

Use of undeclared identifier 'CCJumpBy'

This is my code
#import "Gameplay.h"
#import <CCActionInterval.h>
#implementation Gameplay {
CCPhysicsNode *_physicsNode;
}
- (void)didLoadFromCCB {
// tell this scene to accept touches
self.userInteractionEnabled = TRUE;
}
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
[self jumpRunner];
}
-(void)jumpRunner {
CCNode *spaceship = [CCBReader load:#"Runner"];
id jump = [CCJumpBy actionWithDuration:1 position:ccp(100, 0)
height:50 jumps:1];
[spaceship runAction:jump];
}
#end
It's telling me
Use of undeclared identifier 'CCJumpBy'
How do I fix this to make it work? I don't know what to do.
Thanx in advance
Import cocos2d and you should resolve the error
#import "cocos2d.h"
You probably need to #import the CCJumpBy class's header file.
Also I notice that you're #importing a .m file, which generally you don't do. You probably want to change your import of CCActionInterval to be the .h file, not the .m file.
CCJumpBy is defined in CCActionInterval.h.
Change your import to
#import <CCActionInterval.h>
And you should resolve this error.

Why Xcode doesn't recognize a class I created?

I am new to programming and is in the process of learning objective-c from Big Nerd Ranch. Using x-code, I am trying to create a class. Upon creating the class, X-Code is not recognizing it in main file. I created a new project, then created a new file ensuring the correct target was selected. When I try to type triangle, it says "Use of undeclared identifier." What am I doing wrong? Please help.
This is my header file.
#import <Foundation/Foundation.h>
#interface Triangle : NSObject
{
float lengthSideA;
float lengthSideB;
float lengthSideC;
}
#property float lengthSideA;
#property float lengthSideB;
#property float lengthSideC;
-(float) area;
-(float) perimeter;
-(float) hypothenuse;
#end
And this is my implementation file.
#import "Triangle.h"
#implementation Triangle
#synthesize lengthSideA, lengthSideC, lengthSideB;
-(float) perimeter
{
float a = [self lengthSideA];
float b = [self lengthSideB];
float c = [self lengthSideC];
return a + b + c;
}
-(float) area
{
float a = [self lengthSideA];
float b = [self lengthSideB];
return b * a / 2;
}
-(float) hypothenuse
{
float a = [self lengthSideA];
float b = [self lengthSideB];
return sqrt(a * a + b * b);
}
#end
Add #import "Triangle.h" in the class where you are using your Triangle class. You have to import any external class before you can use it.
First of all check if the file is imported. If it is imported, go to build settings and check if the header of the file is added to the compile sources. Also check if the file is added to the main bundle properly. I hope you selected the tick option which says add the reference of the file while adding the file. Hope it helps :)

Resources