0

まだゲームに取り組んでおり、難易度ごとに「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

私は1つの場所でgameSpeedのみを使用しています。

これはここにあります:

[self schedule:@selector(tryPopMoles:) interval:gameSpeed];

これは私のTimedGameLayer.mの中にあります

gameSpeed変数は私のGameInfo.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;
    }
}

私はここで完全に失われました...

何か案は?

ありがとう

4

1 に答える 1

1

以下のコメントとサンプルコードに基づいて:

.hファイルで宣言された一連の変数があり、.hファイルが複数回インクルードされているため、同じ名前の複数の変数があります。constants.hおよびconstants.mファイルを作成し、そのリストを定数ファイルで定数として宣言する必要があります。

constants.h:
extern const int gameSpeed;

constants.m:
const int gameSpeed = 1;

ちなみに、あなたはgameSpeedをintとして宣言していますが、それにfloat値を割り当てるので、gameSpeedは1に等しくなります。代わりにfloat型を使用してください。

于 2012-09-09T14:12:53.197 に答える