Edit2:我重组了所有标题以使用@class 而不是#import 语言。所有 .m 文件现在都有#import。此处发布的问题似乎已解决。现在有一些 BAD ACCESS 错误,但虽然可能都是同一个根本问题,但这种表现已得到解决
编辑:我刚刚发现了一个叫做“导入循环”的东西。我正在调查这是否存在问题。如果有人对此有任何信息,请告诉我。
不相关的更改会导致不可能的错误-我认为程序中的其他地方存在更深层次的错误或错误,但我只想确认是这种情况。我有 3 个错误,并且已经在不同的 Xcode 项目中重建了程序。我有一些代码示例,但别担心——它们(大部分)是头文件
错误 1
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "PixelSprite.h"
#import "HUDLayer.h"
#import "PixelCharacter.h"
/*typedef enum
{
GameSceneLayerTagGame = 1,
GameSceneLayerTagHUD
}GameSceneLayerTags;*/
@interface GameLayer : CCLayer {
}
@property (assign,readwrite) CGPoint heroStartPoint;
@property (nonatomic, retain) CCTMXTiledMap *tileMap;
@property (nonatomic, retain) CCTMXLayer *background;
@property (assign, readwrite) NSInteger scrollSpeed;
@property (assign, readwrite) PixelCharacter *heroCharacter;
上面的行包含一个编译器错误:未知类型名称“PixelCharacter”。我知道没有拼写错误。我什至甚至复制粘贴类和头文件的名称只是为了确保
+(GameLayer *) sharedGameLayer;
-(id) init;
@end
错误 2
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "HUDButton.h"
@interface HUDLayer : CCLayer {
}
@property (readwrite,assign) CCArray* buttonsArray;
// Working with the buttons
-(void) addHUDButtonOfType:(NSString*)type inSlot:(int)slot;
-(void) addHUDButtonOfType:(NSString*)type;
-(void) removeHUDButton:(HUDButton*)button;
上面的行包含一个编译器错误: Expected a type 这没有意义,因为明确发布了一个类型
-(void) removeHUDButtonOfType:(NSString*)type;
-(void) removeAllButtons;
-(void) buttonsQuery;
@end
错误 3
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
// Get touch location
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
// Verify that touch is on button
BOOL isTouchHandled = CGRectContainsPoint([buttonSprite boundingBox], location);
if (isTouchHandled) {
[buttonSprite setColor:ccRED];
SEL selector = NSSelectorFromString(actionMessage);
GameLayer* layer = [GameLayer sharedGameLayer];
PixelCharacter* heroCharacter = [layer heroCharacter];
上面的行包含一个编译器警告:incompatible pointer types initializing 'PixelCharacter*' with and expression of type 'int *'
[heroCharacter addToDoQueue:selector];
}
return isTouchHandled;
}