Reputation: 1
Hey I have a bit of code that keeps returning an error message, but i can't figure out what the problem is. I am fairly new to Objective-c syntax so it could be something fairly simple, however i can not seem to find the problem. The method is
-(void)setPlayerPosition:(CGPoint) position {
CGPoint tileCoord = [self tileCoordForPosition:position];
int tileGid = [metaLayer tileGIDAt:tileCoord];
if (tileGid) {
NSDictionary *properties = [tileMap propertiesForGID:tileGid];
if (properties) {
NSString *collision = [properties valueForKey:@"Collidable"];
if (collision && [collision compare:@"True"] == NSOrderedSame) {
return;
}
NSString *collectable = [properties valueForKey:@"Collectable"];
if (collectable && [collectable compare:@"True"] == NSOrderedSame) {
[metaLayer removeTileAt:tileCoord];
[foreground removeTileAt:tileCoord];
}
}
}
player.position = position;
}
It returns the error Invalid initializer for the 2nd line and also says that my class may not respond to 'tileCoordForPosition:' Any help would be appreciated!
Upvotes: 0
Views: 228
Reputation: 14391
I assume you are following the article at http://www.raywenderlich.com/1186/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-part-2
So after briefly reading it myself, my guess is you are either missing the method required or are not declaring it properly in your class.
You should have the following method declared and implemented
- (CGPoint)tileCoordForPosition:(CGPoint)position
And it should be in the same class as where you call it on self
[self tileCoordForPosition:position]
If you do have that method implemented in your class then make sure you are declaring it correctly too. Try adding it to the top of your .m
file like so
@interface YourControllerNameHere()
- (CGPoint)tileCoordForPosition:(CGPoint)position;
@end
Upvotes: 1
Reputation: 237060
You need to declare tileCoordForPosition:
in your header so the compiler knows what type it returns (in this case, a CGPoint).
Upvotes: 0