Objective c 麻雀-如何修复SIGABRT错误,游戏初始

Objective c 麻雀-如何修复SIGABRT错误,游戏初始,objective-c,ios5,xcode4,sparrow-framework,Objective C,Ios5,Xcode4,Sparrow Framework,我刚刚开始使用sparrow框架,并一直在关注Gamua自己的“大麻雀教程”。我在教程的第一部分,使用AppScaffold1.3,但是当我试图编译我的基本代码时,它挂起在加载屏幕上,并给我一个SIGABRT错误 我在AppScaffold的GameController.m(见底部)中放置了一个异常断点,并在此处停止: mGame=[[Game alloc]initWithWidth:gameWidth-height:gameHeight] 这也是我唯一的输出: 2012-07-30 07:19

我刚刚开始使用sparrow框架,并一直在关注Gamua自己的“大麻雀教程”。我在教程的第一部分,使用AppScaffold1.3,但是当我试图编译我的基本代码时,它挂起在加载屏幕上,并给我一个SIGABRT错误

我在AppScaffold的GameController.m(见底部)中放置了一个异常断点,并在此处停止:

mGame=[[Game alloc]initWithWidth:gameWidth-height:gameHeight]

这也是我唯一的输出:

2012-07-30 07:19:54.787 AppScaffold[1682:10a03] -[Game initWithWidth:height:]: unrecognized selector sent to instance 0x7553980
(lldb)
我使用的是股票AppScaffold,我唯一改变的是游戏

这是我的游戏。m:

@interface Game : SPSprite
@end

@implementation Game
{
@private
    SPImage *mBackground;
    SPImage *mBasket;
    NSMutableArray *mEggs;
}

- (id)init
{
    if((self = [super init]))
    {
        //load the background image first, add it to the display tree
        //and keep it for later use
        mBackground = [[SPImage alloc] initWithContentsOfFile:@"background.png"];
        [self addChild:mBackground];

        //load the image of the basket, add it to the display tree
        //and keep it for later use
        mBasket = [[SPImage alloc] initWithContentsOfFile:@"basket.png"];
        [self addChild:mBasket];

        //create a list that will hold the eggs,
        //which we will add and remove repeatedly during the game
        mEggs = [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)dealloc
{
    [mBackground release];
    [mBasket release];
    [mEggs release];
    [super dealloc];
}

@end
我已经尽力使用我的基本故障排除策略,但我对Obj-C和Sparrow非常陌生,可以用一只手:)

谢谢

编辑:为了清晰起见,我在此处添加了GameController.m内容:

//
//  GameController.m
//  AppScaffold
//

#import <OpenGLES/ES1/gl.h>
#import "GameController.h"


@interface GameController ()

- (UIInterfaceOrientation)initialInterfaceOrientation;

@end


@implementation GameController

- (id)initWithWidth:(float)width height:(float)height
{
    if ((self = [super initWithWidth:width height:height]))
    {
        float gameWidth  = width;
        float gameHeight = height;

        // if we start up in landscape mode, width and height are swapped.
        UIInterfaceOrientation orientation = [self initialInterfaceOrientation];
        if (UIInterfaceOrientationIsLandscape(orientation)) SP_SWAP(gameWidth, gameHeight, float);

        mGame = [[Game alloc] initWithWidth:gameWidth height:gameHeight];

        mGame.pivotX = gameWidth  / 2;
        mGame.pivotY = gameHeight / 2;

        mGame.x = width  / 2;
        mGame.y = height / 2;

        [self rotateToInterfaceOrientation:orientation animationTime:0];
        [self addChild:mGame];
    }

    return self;
}

- (void)dealloc
{
    [mGame release];
    [super dealloc];
}

- (UIInterfaceOrientation)initialInterfaceOrientation
{
    // In an iPhone app, the 'statusBarOrientation' has the correct value on Startup; 
    // unfortunately, that's not the case for an iPad app (for whatever reason). Thus, we read the
    // value from the app's plist file.

    NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary];
    NSString *initialOrientation = [bundleInfo objectForKey:@"UIInterfaceOrientation"];
    if (initialOrientation)
    {
        if ([initialOrientation isEqualToString:@"UIInterfaceOrientationPortrait"])
            return UIInterfaceOrientationPortrait;
        else if ([initialOrientation isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"])
            return UIInterfaceOrientationPortraitUpsideDown;
        else if ([initialOrientation isEqualToString:@"UIInterfaceOrientationLandscapeLeft"])
            return UIInterfaceOrientationLandscapeLeft;
        else
            return UIInterfaceOrientationLandscapeRight;
    }
    else 
    {
        return [[UIApplication sharedApplication] statusBarOrientation];
    }
}

- (void)rotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
                       animationTime:(double)animationTime
{
    float angles[] = {0.0f, 0.0f, -PI, PI_HALF, -PI_HALF};

    float oldAngle = mGame.rotation;
    float newAngle = angles[(int)interfaceOrientation];

    // make sure that rotation is always carried out via the minimal angle
    while (oldAngle - newAngle >  PI) newAngle += TWO_PI;
    while (oldAngle - newAngle < -PI) newAngle -= TWO_PI;

    // rotate game
    if (animationTime)
    {
        SPTween *tween = [SPTween tweenWithTarget:mGame time:animationTime
                                       transition:SP_TRANSITION_EASE_IN_OUT];
        [tween animateProperty:@"rotation" targetValue:newAngle];
        [[SPStage mainStage].juggler removeObjectsWithTarget:mGame];
        [[SPStage mainStage].juggler addObject:tween];
    }
    else 
    {
        mGame.rotation = newAngle;
    }

    // inform all display objects about the new game size
    BOOL isPortrait = UIInterfaceOrientationIsPortrait(interfaceOrientation);
    float newWidth  = isPortrait ? MIN(mGame.gameWidth, mGame.gameHeight) : 
                                   MAX(mGame.gameWidth, mGame.gameHeight);
    float newHeight = isPortrait ? MAX(mGame.gameWidth, mGame.gameHeight) :
                                   MIN(mGame.gameWidth, mGame.gameHeight);

    if (newWidth != mGame.gameWidth)
    {
        mGame.gameWidth  = newWidth;
        mGame.gameHeight = newHeight;

        SPEvent *resizeEvent = [[SPResizeEvent alloc] initWithType:SP_EVENT_TYPE_RESIZE
                                width:newWidth height:newHeight animationTime:animationTime];
        [mGame broadcastEvent:resizeEvent];
        [resizeEvent release];
    }
}

// Enable this method for the simplest possible universal app support: it will display a black
// border around the iPhone (640x960) game when it is started on the iPad (768x1024); no need to 
// modify any coordinates. 
/*
- (void)render:(SPRenderSupport *)support
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        glEnable(GL_SCISSOR_TEST);
        glScissor(64, 32, 640, 960);
        [super render:support];
        glDisable(GL_SCISSOR_TEST);
    }
    else 
        [super render:support];
}
*/

@end
//
//GameController.m
//应用脚手架
//
#进口
#导入“GameController.h”
@接口控制器()
-(UIInterfaceOrientation)初始界面定向;
@结束
@游戏控制器的实现
-(id)initWithWidth:(浮动)宽度高度:(浮动)高度
{
if((self=[super initWithWidth:width-height:height]))
{
浮动游戏宽度=宽度;
浮动游戏高度=高度;
//如果我们以横向模式启动,则宽度和高度将交换。
UIInterfaceOrientation方向=[self initialInterfaceOrientation];
if(UIInterfaceOrientationIsLandscape(方向))SP_交换(游戏宽度、游戏高度、浮动);
mGame=[[Game alloc]initWithWidth:gameWidth-height:gameHeight];
mGame.pivotX=游戏宽度/2;
mGame.pivotY=游戏高度/2;
mGame.x=宽度/2;
mGame.y=高度/2;
[自旋转接口方向:方向动画时间:0];
[self addChild:mGame];
}
回归自我;
}
-(无效)解除锁定
{
[mGame发布];
[super dealoc];
}
-(UIInterfaceOrientation)初始InterfaceOrientation
{
//在iPhone应用程序中,“statusBarOrientation”在启动时具有正确的值;
//不幸的是,iPad应用程序并非如此(无论出于何种原因)
//应用程序的plist文件中的值。
NSDictionary*bundleInfo=[[NSBundle mainBundle]infoDictionary];
NSString*initialOrientation=[bundleInfo objectForKey:@“UIInterfaceOrientation”];
如果(初始方向)
{
if([initialOrientation isEqualToString:@“UIInterfaceOrientationPortrait”])
返回UIInterfaceOrientationPortrait;
else if([initialOrientation isEqualToString:@“UIInterfaceOrientationGraphitalUpsideDown”])
返回UIInterfaceOrientationGraphicalUpsidedown;
else if([initialOrientation IsequalString:@“UIInterfaceOrientationAndscapeLeft”])
返回UIInterfaceOrientation和scapeLeft;
其他的
返回UIInterfaceOrientation和SCAPERight;
}
其他的
{
返回[[UIApplication sharedApplication]statusBarOrientation];
}
}
-(空)旋转接口定向:(UIInterfaceOrientation)接口定向
animationTime:(双)animationTime
{
浮动角度[]={0.0f,0.0f,-PI,PI_-HALF,-PI_-HALF};
float oldAngle=mGame.rotation;
float newAngle=角度[(int)接口方向];
//确保始终以最小角度进行旋转
而(oldAngle-newAngle>PI)newAngle+=TWO_-PI;
而(oldAngle-newAngle<-PI)newAngle-=2_-PI;
//轮换赛
如果(动画时间)
{
SPTween*tween=[SPTween tween-withtarget:mGame-time:animationTime
转换:SP_转换_缓解_输入_输出];
[tween animateProperty:@“旋转”目标值:newAngle];
[[SPStage mainStage].juggler移除目标为:mGame]的对象;
[[SPStage mainStage]。杂耍者添加对象:tween];
}
其他的
{
mGame.rotation=新角度;
}
//通知所有显示对象新游戏大小
BOOL isPortrait=UIInterfaceOrientationSportrait(interfaceOrientation);
float newWidth=isPortrait?MIN(mGame.gameWidth,mGame.gameHeight):
最大值(mGame.gameWidth、mGame.gameHeight);
float newHeight=isPortrait?MAX(mGame.gameWidth,mGame.gameHeight):
最小值(mGame.gameWidth,mGame.gameHeight);
if(newWidth!=mGame.gameWidth)
{
mGame.gameWidth=newWidth;
mGame.gameHeight=新高度;
SPEvent*resizeEvent=[[SPResizeEvent alloc]initWithType:SP\u EVENT\u TYPE\u RESIZE
宽度:新宽度高度:新高度动画时间:动画时间];
[mGame broadcastEvent:resizeEvent];
[resizeEvent release];
}
}
//启用此方法以获得最简单的通用应用程序支持:它将显示黑色
//iPhone(640x960)游戏在iPad(768x1024)上启动时的边框;没必要
//修改任何坐标。
/*
-(void)渲染:(SPRenderSupport*)支持
{
if(UI\u USER\u INTERFACE\u IDIOM()==UIUserInterfaceIdiomPad)
{
glEnable(GL_剪刀试验);
glScissor(64,32,640,960);
[超级渲染:支持];
glDisable(GLU剪式试验);
}
其他的
[超级渲染:支持];
}
*/
@结束
这是我的Xcode项目:

您正在调用

initWithWidth:height:
方法,而在类中未定义任何

从您的编辑中,似乎
initWithWidth
方法是在类
GameController
中声明的,而不是在
Game
中声明的

所以,看起来

在哪个上下文中调用
initWithWidth:height:
方法在
Game.h
中声明,但在
GameController.m
中定义

这解释了为什么在编译时会出现SIGABRT和错误

修理工来了

mGame = [[GameController alloc] init];
从GameController InitWidth

- (id)initWithWidth:(float)width height:(float)height
{
if ((self = [super initWithWidth:width height:height]))
{
    float gameWidth  = width;
    float gameHeight = height;

    // if we start up in landscape mode, width and height are swapped.
    UIInterfaceOrientation orientation = [self initialInterfaceOrientation];
    if (UIInterfaceOrientationIsLandscape(orientation)) SP_SWAP(gameWidth, gameHeight, float);

    mGame = [[Game alloc] init];

    mGame.pivotX = gameWidth  / 2;
    mGame.pivotY = gameHeight / 2;

    mGame.x = width  / 2;
    mGame.y = height / 2;

    [self rotateToInterfaceOrientation:orientation animationTime:0];
    [self addChild:mGame];
}

return self;
}

这本教程很古老,而且很有趣
- (id)init
{
    if((self = [super init]))
    {
- (id)initWithWidth:(float)width height:(float)height
{
    if ((self = [super initWithWidth:width height:height]))
    {