Xcode question

inside the AppController.mm’s - (void) applicationDidBecomeActive:(UIApplication*)application function
I have this code;

UIImageView *myImage = [[UIImageView alloc] initWithFrame: _window.frame]; 
[myImage setImage:[UIImage imageNamed:@"Background.png"]];
[_window insertSubview:myImage atIndex:0];
//[_window addSubview:myImage];
[myImage release];

It supposed to display the “Background.PNG” on a screen.
It works perfectly fine when I create an empty xcode project and use it inside the AppDelegate.m, however its not doing anything when I built the application with unity.

Thanks

actually something like this should work. Probably you did this to early. Did go through unitys appcontroller and check when the window and eagl view are set up?
I did something like this in Rolls Royce ghost, where i had the complete GUI elemnents in a UIView, which was controlled by a UIViewcontroller and that succesfully was on top of the unity glview.

But that was unity 1.7, i don´t know about changes in 3.0

  • Marjan
    I checked the appcontroller, but I don’t even know where to look I’ve never used xcode before. Just for testing purposes I put the code inside the -applicationDidFinishLaunching funtion, but no luck :frowning: I don’t know what’s wrong with the code. Its been 2 days and still no solution.

ok, i had a quick look, and it works. But maybe not what you want. Seems you want to have a background image. Means behind unity.
That would not be visible, because, well, its behind unity.

You use:
[_window insertSubview:myImage atIndex:0];

Which means you put the imageview in the very background. atIndex:0 means bottommost.

If you want something on top, do this (refers to unity 3)

open the appcontroller and look for the methode OpenEAGL_UnityCallback. Thats where the window and EAGLView are being set up.

Right before the return statement paste this:

UIImageView *myImage = [[UIImageView alloc] initWithFrame: _window.frame];
[myImage setImage:[UIImage imageNamed:@“Icon.png”]];
[_window insertSubview:myImage aboveSubview:view];
[myImage release];

This will put a fullscreen image over unity. Which you probably don´t want.

To make it a certain size change the firstline to something like this:
UIImageView *myImage = [[UIImageView alloc] initWithFrame: CGRect(20,20,100,100)];

also, i don´t see the point in doing this. If you want to have some functionality with this you would rather write a UIViewcontroller, programm the interactivity in there and put its view on top, instead of just an imageview.

In case you really wanted a background image, well, then you need to see if something like
view.opaque = NO;

works. But since unity always uses a camera background color and clearflag, that might not help. You need to play around with that.

-marjan

Thanks for the help at least it displays the image right now.

The reason I’m using this; when user hits the home button, and re-enter the game it takes several seconds for the game to come back. I want to put some sort of loading screen until the game comes back, so I can at least indicate that the game is not frozen.

I used the code you gave me just before OpenEAGL_UnityCallback’s return and it displays the image, but the problem is it displays it forever. It never shows the actual game. I tried it inside the applicationDidBecomeActive function, but it seems like its not even using that function.

Thanks again

Thanks

Well, yeah, as soon as you start with things like that in becomes timeconsuming and difficult.

One tip: Try adding a NSLog(@“test functionname”), into every function you see there and then run the game and look into the consoles log.
This way you can quickly see, at what time which function is being executed.
Much faster then trying to put in code that should display something here and there and not being sure if that even works.

Depending of what you want to do the effort might be wort it because once you get along after 2 - 4 weeks you are able to use things like your own cocoa gui, use Safari, maps, activity indicator in your game, store data in more eficient ways, get the game load quicker, don´t hassle with imageslideshows requiring you to convert images to textures and and and.

I had no idea about xcode but after four weeks learning i was able to do these rather basic things.
Only draw back is, you cannot get such an app easily to other plattforms as a lot of parts are xcode only and would need to be rewritten completly.

Good luck!