仍然在我的游戏中工作,对于每个难度我都有一个"gameSpeed“,这是根据选择的难度而设置的。
然而,当我尝试运行我的应用程序时,我得到了以下错误:
duplicate symbol _gameSpeed in:
/Users/Ashley/Library/Developer/Xcode/DerivedData/Whack-etfeadnxmmtdkgdoyvgumsuaapsz/Build/Intermediates/Whack.build/Debug-iphonesimulator/Whack.build/Objects-normal/i386/TimedGameLayer.o
/Users/Ashley/Library/Developer/Xcode/DerivedData/Whack-etfeadnxmmtdkgdoyvgumsuaapsz/Build/Intermediates/Whack.build/Debug-iphonesimulator/Whack.build/Objects-normal/i386/GameInfo.o
ld: 1 duplicate symbols for architecture i386
collect2: ld returned 1 exit status
Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1我只在一个位置使用gameSpeed。
它在这里:
[self schedule:@selector(tryPopMoles:) interval:gameSpeed];这在我的TimedGameLayer.m中
gameSpeed变量在我的游戏信息.h中
我像这样导入头部:
#import "GameInfo.h"我的GameInfo.h如下所示:
@interface GameInfo : NSObject
+(void)setupGame:(enum GameType)type withArg2:(enum GameDifficulty)difficulty;
+(void)resetGame;
+(void)togglePause;
@end
//Game Type
enum GameType gameType;
enum GameDifficulty gameDifficulty;
//Release Version
NSString *version;
//Settings
int gameSpeed = 1.5;
//Stats
int touches = 0;
int score = 0;
int totalSpawns = 0;
//usables
bool gamePaused = FALSE;
typedef enum GameType {
GameTypeClassic = 0,
GameTypeUnlimited,
GameTypeTimed,
GameTypeExpert,
} GameType;
typedef enum GameDifficulty
{
GameDifficultyEasy = 0,
GameDifficultyMedium,
GameDifficultyHard,
} GameDifficulty;我的setupGame函数(在我的GameInfo.m文件中)如下所示:
+(void)setupGame:(enum GameType)type withArg2:(enum GameDifficulty)difficulty
{
gameType = type;
gameDifficulty = difficulty;
switch(gameDifficulty)
{
case GameDifficultyEasy:
gameSpeed = 1.5;
break;
case GameDifficultyMedium:
gameSpeed = 1.0;
break;
case GameDifficultyHard:
gameSpeed = 0.5;
break;
}
}我完全迷失在这里..。
有什么想法吗?
谢谢
发布于 2012-09-09 22:12:53
基于您下面的注释和示例代码:
您在.h文件中声明了一系列变量,并且多次包含.h文件,因此您有多个同名的变量。您应该创建一个constants.h和constants.m文件,并在常量文件中将该列表声明为常量。
constants.h:
extern const int gameSpeed;
constants.m:
const int gameSpeed = 1;顺便说一句,您将gameSpeed声明为一个整数,但是为它分配了一个浮点值,因此gameSpeed将等于1。
https://stackoverflow.com/questions/12339780
复制相似问题