iossparrow-framework

Adding SPView to an existing iOS project shows pink screen (Sparrow Framework)


I am trying to add some particle effects to my iPhone application. My project is created using traditional UIKit. I am not using the AppScaffold template, so I have to add and setup sparrow manually. I did #import "Sparrow.h", and it built just fine.

The problem is when I tried to add a SPView. It just show a blank pink view. I don't know what I did wrong. Here is my code snippet:

Game.h

@implementation Game
- (id)initWithWidth:(float)width height:(float)height
{
    if (self = [super initWithWidth:width height:height])
    {
        SPQuad *quad = [SPQuad quadWithWidth:100 height:100];
        quad.color = 0xff0000;
        quad.x = 50;
        quad.y = 50;
        [self addChild:quad];
    }
    return self;
}
@end

In a viewController's viewDidload...

- (void)viewDidLoad {
    [super viewDidLoad];
    // sparrow
    SP_CREATE_POOL(pool);    

    [SPStage setSupportHighResolutions:YES];

    SPView *spv = [[SPView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:spv];
    [spv release];

    spv.frameRate = 30;

    Game *game = [[Game alloc] init];
    spv.stage = game;
    [game release];
    [spv start];

    SP_RELEASE_POOL(pool);
}

Additional weird symptoms are that I have created a UIView in .xib file and changed it class to SPView. But when I use that view, the compiler still recognize it as a UIView. It's like xCode can see the header file but the compiler somehow doesn't. Another issue is I tried to use a method 'SPImage *background = [SPImage imageWithContentsOfFile:@"camera_test.png"];', but when I run it, it gives this error reason: '+[NSBundle appBundle]: unrecognized selector sent to class 0x7a6890'. Which means that it cannot find the sparrow category method 'appBundle'. But this method does EXIST in the source code! and it compile with no problem. It just crash at run time.

I double checked the build settings and I think I have everything setup correctly, such as 'Other linker flags' as -ObjC -load_all. I have no idea what's the problem.


Solution

  • I found the solution. In the target's "Build Settings", I have to set -ObjC -all_load in 'Other Linker Flags' for BOTH Target and Project columns. The setting for the Target column was whited-out so I think there is nothing, but actually there is actually a value in it!. I spent a day going through each build settings option in Sparrow 'AppScaffold' project and found this unintentionally. This is very tricky. Even -ObjC -all_load is set in Project but not in Target, the project still build just fine but it will not work or even crash at runtime.

    'Other Linker Flags' when NOT highlighted. 'Other Linker Flags' setting when NOT highlighted.

    'Other Linker Flags' when highlighted. Ugh! There is something in target (AggScaffold) column! 'Other Linker Flags' setting when highlighted. ugh! There is something in target (AggScaffold) column!

    I suggest the Sparrow framework staffs to include this information in their tutorial. Missing even a small detail like this could cause someone a whole day fixing it.

    Hope this helps.

    PS. Link to this question of mine in sparrow forum: http://forum.sparrow-framework.org/topic/adding-spview-to-a-uiview