pch文件中的编译器错误:无法找到UIKit.h

时间:2014-08-05 00:11:33

标签: objective-c xcode

这是我的MainLayer.m文件代码:

/*
 * Kobold2D™ --- http://www.kobold2d.org
 *
 * Copyright (c) 2010-2011 Steffen Itterheim.
 * Released under MIT License in Germany (LICENSE-Kobold2D.txt).
 */

#import "MainLayer.h"
#import "SimpleAudioEngine.h"
#import "Floor.h"
#import "kobold2d.h"

@interface MainLayer (PrivateMethods)
@end

@implementation MainLayer

// Settings


// Declare manager constants
SimpleAudioEngine const *audioEngine;
CCDirector const *director;
KKInput const *input;
NSUserDefaults const *userDefaults;
float globalScale;

// Declare global variables
NSMutableArray *floors;
CCSprite *box, *vignette, *boxShadow;
CCLabelTTF *title, *startPrompt, *scoreLabel, *highScoreLabel, *scorePanel;
CGPoint screenCenter;

- (id)init {
    if (self = [super init]) {
        // Initialize constants
        audioEngine = [SimpleAudioEngine sharedEngine];
        director = [CCDirector sharedDirector];
        input = [KKInput sharedInput];
        userDefaults = [NSUserDefaults standardUserDefaults];

        // Enable tilt
        input.accelerometerActive = YES;
        input.acceleration.filteringFactor = .2;

        // Initialize game sprites
        box = [CCSprite spriteWithFile:@"box.png"];
        boxShadow = [CCSprite spriteWithFile:@"shadow.png"];
        scorePanel = [CCSprite spriteWithFile:@"end.png"];

        // Get high score
        highScore = [[userDefaults objectForKey:@"highScore"] integerValue];

        // Setup & render scene
        glClearColor(.96, .96, .96, 1);
        screenCenter = director.screenCenter;
        globalScale = director.screenSize.height / 960;

        floors = [NSMutableArray new];
        for (int i = 0; i < 3; i++) {
            Floor *floor = [[Floor alloc] initWithDepth:4 - i];
            floor.sprite.opacity = floor.sprite.scale * 255;

            [floors addObject:floor];
            [self addChild:floor.sprite];
            [self reorderChild:floor.sprite z:-(int)floor.depth];
        }

        boxShadow.position = director.screenCenter;
        boxShadow.scale = globalScale;
        boxShadow.opacity = .5;
        [self addChild:boxShadow];
        [self reorderChild:boxShadow z:0];

        box.position = director.screenCenter;
        box.scale = globalScale;
        [self addChild:box];
        [self reorderChild:box z:0];

        scorePanel.position = director.screenCenter;
        scorePanel.scale = 0;
        scorePanel.opacity = 0;

        // Add labels
        title = [CCSprite spriteWithFile:@"title.png"];
        title.position = CGPointMake(director.screenCenter.x,
                                     director.screenCenter.y + 250 * globalScale);
        title.scale = globalScale;
        [self addChild:title];

        startPrompt = [CCLabelTTF labelWithString:@"Tap to Start"
                                         fontName:@"Michroma"
                                         fontSize:30];
        startPrompt.position = CGPointMake(director.screenCenter.x,
                                           director.screenCenter.y - 250 * globalScale);
        startPrompt.color = ccGRAY;
        [self addChild:startPrompt];

        scoreLabel = [CCLabelTTF labelWithString:@"0"
                                        fontName:@"Michroma"
                                        fontSize:100];
        scoreLabel.position = CGPointMake(director.screenCenter.x,
                                          director.screenCenter.y - 150 * globalScale);
        scoreLabel.color = ccGRAY;

        highScoreLabel = [CCLabelTTF labelWithString:@"0"
                                            fontName:@"Michroma"
                                            fontSize:100];
        highScoreLabel.position = CGPointMake(director.screenCenter.x,
                                              director.screenCenter.y - 95 * globalScale);
        highScoreLabel.color = ccGRAY;
        highScoreLabel.opacity = 0;

        [self scheduleUpdate];
    }

    return self;
}

float velocity = 0, acceleration = .05;
float posX = 0, posY = 0;

int score = -1, highScore = 0;

int const START = 0, PREPLAY = 1, PLAY = 2, POSTPLAY = 3, END = 4, REPLAY = 5;
int gameState = 0;

Floor *lastClosestFloor;

float animStep = 0;
float const animTime = .4;
bool animReversed = FALSE;

bool prevTouchDown = FALSE;

- (void)update:(ccTime)delta {
    float animProg;
    switch (gameState) {
        case START:
            if (input.touchesAvailable) {
                box.scale = 1.2 * globalScale;
            }

            if (!animReversed) {
                animStep += delta;
                if (animStep >= animTime) {
                    animReversed = YES;
                    animStep = animTime;
                }
            } else {
                animStep -= delta;
                if (animStep <= 0) {
                    animReversed = NO;
                    animStep = 0;
                }
            }

            animProg = animStep / animTime;
            startPrompt.opacity = (1 - animProg) * 255;

            if (!input.touchesAvailable && prevTouchDown) {
                box.scale = globalScale;

                prevTouchDown = NO;
                animStep = 0;

                NSLog(@"Entering PREPLAY stage");
                gameState = PREPLAY;
                return;
            }
            prevTouchDown = input.touchesAvailable;

            for (int i = 0; i < [floors count]; i++) {
                Floor *floor = [floors objectAtIndex:i];
                floor.sprite.position = CGPointMake(director.screenCenter.x
                                                    - floor.sprite.scale / globalScale
                                                    * (director.screenSize.width / 2
                                                       * input.acceleration.smoothedX
                                                       - floor.offsetX),
                                                    director.screenCenter.y
                                                    - floor.sprite.scale / globalScale
                                                    * (director.screenSize.height / 2
                                                       * input.acceleration.smoothedY
                                                       - floor.offsetY));
            }

            return;
        case PREPLAY:
            animStep += delta;
            animProg = animStep / animTime;

            if (animProg >= 1) {
                box.rotation = 0;
                [self removeChild:title];
                [self removeChild:startPrompt];
                [self addChild:scoreLabel];
                [self reorderChild:scoreLabel z:1];

                animStep = 0;

                NSLog(@"Entering PLAY stage");
                gameState = PLAY;
                return;
            }

            box.rotation = (1 - (animProg-1) * (animProg-1)) * 90;

            title.opacity = (1 - animProg) * 255;
            int promptOpacStart = startPrompt.opacity;
            startPrompt.opacity = (1 - animProg) * promptOpacStart;

            return;
        case PLAY:
            break;
        case POSTPLAY:
            animStep += delta;
            animProg = animStep / animTime;

            if (animProg >= 1) {

                animStep = 0;

                NSLog(@"Entering END state");
                gameState = END;
                return;
            }

            scorePanel.scale = (1 - (animProg-1) * (animProg-1)) * globalScale;
            box.scale = (1-animProg) * (1-animProg);
            scoreLabel.opacity = animProg * 255;
            highScoreLabel.opacity = animProg * 255;
            scorePanel.opacity = animProg * 255;

            return;
        case END:
            if (input.touchesAvailable) {
                box.scale = 1.2 * globalScale;
            }

            if (!animReversed) {
                animStep += delta;
                if (animStep >= animTime) {
                    animReversed = YES;
                    animStep = animTime;
                }
            } else {
                animStep -= delta;
                if (animStep <= 0) {
                    animReversed = NO;
                    animStep = 0;
                }
            }

            animProg = animStep / animTime;
            startPrompt.opacity = (1 - animProg) * 255;

            if (!input.touchesAvailable && prevTouchDown) {
                box.scale = globalScale;

                prevTouchDown = NO;
                animStep = 0;

                NSLog(@"Entering REPLAY stage");
                gameState = REPLAY;
                return;
            }
            prevTouchDown = input.touchesAvailable;

            for (int i = 0; i < [floors count]; i++) {
                Floor *floor = [floors objectAtIndex:i];
                floor.sprite.position = CGPointMake(director.screenCenter.x
                                                    - floor.sprite.scale / globalScale
                                                    * (director.screenSize.width / 2
                                                       * input.acceleration.smoothedX
                                                       + posX - floor.offsetX),
                                                    director.screenCenter.y
                                                    - floor.sprite.scale / globalScale
                                                    * (director.screenSize.height / 2
                                                       * input.acceleration.smoothedY
                                                       + posY - floor.offsetY));
            }

            return;
        case REPLAY:
            animStep += delta;
            animProg = animStep / animTime;

            if (animProg >= 1) {
                box.rotation = 0;
                [self removeChild:startPrompt];
                [self removeChild:highScoreLabel];
                [self removeChild:scorePanel];

                posX = posY = velocity = 0;

                score = 0;
                [scoreLabel setString:@"0"];

                for (int i = 0; i < [floors count]; i++) {
                    Floor *floor = [floors objectAtIndex:i];

                    floor.depth = 4 - i;
                    [floor regeneratePosition];
                }

                scoreLabel.position = CGPointMake(director.screenCenter.x,
                                                  director.screenCenter.y - 150 * globalScale);

                animStep = 0;

                NSLog(@"Entering PLAY stage");
                gameState = PLAY;
                return;
            }

            box.rotation = (1 - (animProg-1) * (animProg-1)) * 90;

            title.opacity = (1 - animProg) * 255;
            promptOpacStart = startPrompt.opacity;
            startPrompt.opacity = (1 - animProg) * promptOpacStart;

            return;
    }

    velocity += acceleration * delta;
    if (velocity >= 1) velocity = 1;

    Floor *closestFloor = [[Floor alloc] initWithDepth:INFINITY];
    for (int i = 0; i < 3; i++) { // Update each floor
        Floor *floor = [floors objectAtIndex:i];

        // Update physics
        floor.depth -= velocity * delta;

        if (floor.depth <= 0) { // Passed screen, reset depth
            floor.depth = [floors count];
            [floor rgeneratePosition];
        }

        if (floor.depth < closestFloor.depth && floor.depth > 1) { closestFloor = floor; }

        posX += input.acceleration.smoothedX * delta * 1024;
        posY += input.acceleration.smoothedY * delta * 1024;

        // Update graphics parameters
        floor.sprite.scale = globalScale / floor.depth;
        [self reorderChild:floor.sprite z:-(int)floor.depth];

        if (floor.depth > 1) { floor.sprite.opacity = floor.sprite.scale / globalScale * 255; }
        else { floor.sprite.opacity = floor.depth * 255; }

        for (int i = 0; i < [floors count]; i++) {
            Floor *floor = [floors objectAtIndex:i];
            floor.sprite.position = CGPointMake(director.screenCenter.x
                                                - floor.sprite.scale / globalScale
                                                * (posX - floor.offsetX),
                                                director.screenCenter.y
                                                - floor.sprite.scale / globalScale
                                                * (posY - floor.offsetY));
        }
    }

    // Update box shadow
    boxShadow.scale = globalScale * closestFloor.depth;
    boxShadow.opacity = 255. * (2 - closestFloor.depth);

    // Update score
    if (closestFloor.depth > lastClosestFloor.depth) { // New layer passed
        if (fabs(posX - lastClosestFloor.offsetX) > 27
            || fabs(posY - lastClosestFloor.offsetY) > 27) { // Collision!

            [self addChild:scorePanel];
            scoreLabel.position = CGPointMake(director.screenCenter.x,
                                              director.screenCenter.y + 110 * globalScale);
            [highScoreLabel setString:[NSString stringWithFormat:@"%d", highScore]];
            [self addChild:highScoreLabel];

            NSLog(@"Entering POSTPLAY stage");
            gameState = POSTPLAY;
            return;
        }

        score++;
        [scoreLabel setString:[NSString stringWithFormat:@"%d", score]];
        if (score > highScore) {
            highScore = score;
            [userDefaults setInteger:highScore forKey:@"highScore"];
        }
    }

    lastClosestFloor = closestFloor;

}

@end

我收到一条错误消息:“/ Users / teen / Desktop / Gravity Sieve all files / Projectfiles / Prefix-iOS.pch:23:9:'UIKit / UIKit.h'文件未找到”

我不知道出了什么问题。如果有人需要我的其他文件的代码,我会把它们提供给你们,看看你是否需要那些代码来回答我的问题。

这里是Prefix-IOS.pch文件代码:

/*
 * Kobold2D™ --- http://www.kobold2d.org
 *
 * Copyright (c) 2010-2011 Steffen Itterheim. 
 * Released under MIT License in Germany (LICENSE-Kobold2D.txt).
 */

//
// Prefix header for all source files of the project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif

#ifdef __OBJC__

// iOS SDK headers
#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>
#import <UIKit/UIKit.h>

// Cocos2D headers
#import "cocos2d.h"

// Kobold2D headers
#import "kobold2d.h"
#import "kkARCSupport.h"

// Wax (and Lua) headers
#import "luawax.h"

#endif // __OBJC__


// C++ header files
#ifdef __cplusplus

#endif // __cplusplus

1 个答案:

答案 0 :(得分:0)

很可能你忘了链接UIKit。