Use of undeclared identifier 'CCJumpBy' - ios

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.

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

Multiple data objects by extension using a protocol

I had the great idea to use a a protocol on the UITouch class to extend it with some methods declared in the protocol. The reason of such a construct is to provide the protocol inside a framework to other users that they can send UITouch-similar data objects (Because they can't create a native UITouch object).
The protocol (myProtocol.h) is quite easy:
// myProtocol.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#protocol myProtocol <NSObject>
- (CGFloat) MYPREFIX_radius;
#end
Now i have a simple extension on UITouch using that protocol
// UITouch+MYPREFIX_Extension.h
#import <UIKit/UIKit.h>
#import "myProtocol.h"
#interface UITouch (MYPREFIX_Extension) <myProtocol>
#end
and
// UITouch+MYPREFIX_Extension.m
#import "UITouch+MYPREFIX_Extension.h"
#implementation UITouch (MYPREFIX_Extension)
- (CGFloat) MYPREFIX_radius {
return self.majorRadius;
}
#end
By this everything is good to me. Now I built a touchRecognizer.
// touchRecognizer.h
#import <UIKit/UIKit.h>
#interface touchRecognizer : UITouch
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
#end
In the touchRecognizer.m the problem begins. There I cast the UITouch object to a NSObject by using the protocol.And then I simply want to get access to the newly defined method MYPREFIX_radius and it should give me back the UITouch.major_radius.
// touchRecognizer.m
#import "touchRecognizer.h"
#import "UITouch+MYPREFIX_Extension.h"
#interface touchRecognizer()
#end
#implementation touchRecognizer
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for(NSObject<myProtocol> *touch in touches) {
NSLog(#"radius %f", touch.MYPREFIX_radius);
}
}
#end
But when I run the code it just gives me the Error
-[UITouch MYPREFIX_radius]: unrecognized selector sent to instance 0x1701887b0
I don't understand it. What do I miss?
Thank you for your help.
I am guessing you forget to add the implementation file (UITouch+MYPREFIX_Extension.m) to your build target

No visible #interface error using enumerateChildNodesWithName?

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

Disabling CALayer implicit animations

The class below is attempting to stop any implicit animations from occurring when a CALayer has a property changed.
// NoImplicitAnimations.h
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#interface NoImplicitAnimations : NSObject
- (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key;
#end
// NoImplicitAnimations.m
#import "NoImplicitAnimations.h"
#implementation NoImplicitAnimations
- (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key {
return (id)[NSNull null];
}
#end
I import NoImplicitAnimations.h in my Objective-C to Swift bridging header.
I create a global constant let _noImplicitAnimations = NoImplicitAnimations().
I extend the CALayer class like so:
extension CALayer {
func noImplicitAnimations () {
delegate = _noImplicitAnimations
}
}
Now comes the problem. I use myLayer.noImplicitAnimations() right after I create myLayer. Yet, implicit animations are still happening.
What am I doing wrong here?
Nevermind. This actually does work. I was testing it on the wrong CALayer. My bad!

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.

Resources