a timed transition between scenes in Xcode - xcode

I am using a storyboard on xcode and I need help making a timed transition between 2 scenes. I want the game to open on one scene and after 5 seconds go to the actual game scene. Any help would be very appreciated! thanks!

You can use a NSTimer for that:
In the header (.h) file you create the timer:
NSTimer *timer;
In the .m file you can use this code:
(above #interface put #import "SecondView.h")
-(void)viewScene {
SecondView *second = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
second.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:second animated:true completion:nil];
}
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(viewScene) userInfo:nil repeats:NO];
Good luck!

If you are talking about splash screen(image) then you could do that only saving three image named Default.png, Default#2x.png, Default-568h#2x.png in the project directory. There are for normal screen (320*480), 3.5 retina screen (640*960), 4.0 retina screen (640*1136) images.

Related

NSTimer on UIToolbar

In my project I am implementing NSTimer to calculate time.
What I want to do is,
I am having my UIToolBar in my Timer.m file with tag 100.
and I want to add NSTimer on my UIToolBar from TimerController.m
But I am not able to add NStimer on UIToolBar.
My Timer is getting added over my navigation bar.
How to add my Timer on UIToolbar.
Can any one guide me.
Thanks in advance.
Here is my code...
Timer.m
UIToolbar* bottomToolbar = [[UIToolbar alloc] init];
bottomToolbar.frame = CGRectMake(0, 390, self.frame.size.width, 44);
[bottomToolbar sizeToFit];
bottomToolbar.tintColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
bottomToolbar.tag = 100;
[self addSubview:bottomToolbar];
and this is my time in TimerController.h
NSTimer* timer;
}
#property (nonatomic,retain) NSTimer* timer;
and code for this timer in TimerController.m
timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(displayTime) userInfo:nil repeats:YES];
and in displayTime method I will go for timing calculation.
I didn't found ant property to add timer over UIToolBar.
I tried using below code, but it give me warning with no output.
Warning as "incompatible pointer types sending NStimer* to prameter of UIView*"
UIToolbar *bottomBar = (UIToolbar*)[self.view viewWithTag:100];
[bottomBar addSubview:timer];
Here is the image how I want it....
#note :- I also checked whether my Toolbar tag is getting problem, but NO,
I am able to add UIToolbar and nslog tag correctly.
Thanks in advance

How to change image within a customised UIImageView class

I'm new to Xcode. This is probably a very simple question to you, but I wonder if anyone can help me.
What I want to do is to load an image in a customised UIImageView, when clicking the image, the imageview will change to another image. When I run the simulator, there are no error messages, but the second image does not load after clicking.
I've declared a UIImageView subclass dragView. In the dragView.m, I have such codes:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self changePicture];
}
-(void) changePicture {
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"] stringByAppendingPathComponent:#"Red Flower.png"];
self.image = [UIImage imageWithContentsOfFile:path];
}
By the way, I have enabled the interaction. Many thanks!
You probably need to tell the OS to update the view by calling [self setNeedsDisplay:YES].

UIBarButtonType as a UIButton. Not on a NavigationBar!

I would like to use the better styled UIBarButtonType as a typical UIButton. This is just to use on a view not a navigationBar.
I don't really want to recreate the button in an image app and apply to the various states. I know how to do it the other way around so there must be a way.
Please help.
I tried this and it works :
UIButton *info = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIBarButtonItem *infoBis = [[UIBarButtonItem alloc] initWithCustomView:info];
NSArray *array = [[NSArray alloc] initWithObjects:infoBis, nil];
[tool setItems:array animated:YES]; //tool = UIToolbar
don't forget to put a target on your UIBarButtonItem ;)
You cannot do that.
UIBarButtonItems are made just for UIToolbar and UINavigationBar.
You need to create your own background image. It isn't a big issue, just few lines.

Xcode : Wallpapers with UIButton

I want to make an wallpaper iphone app.
Now if i have for example 100 wallpapers , do I have to create 100 nib files and 100 .m and .h files and 100 UIButtons for to save the wallpaper and 100 UIButton for to go to the previous or next wallpaper ?
Is there any other way to do this ?
Thanks !
yes sure.
save your hundred wallpapers in the resources folder. The are named like this "wp_1.png", "wp_2.png" etc.
Then you create a nib with the buttons (previous, next and save)
In the uiviewcontroller you'll have an int property. For instance you call it n or something like that. I would suggest adding another property for your wallpaper (UIImageView) Then you implement the methods in the view controller.
-(void)awakeFromNib {
self.n = 1;
UIImage* wallpaper = [UIImage imageNamed:#"wp_1.png"];
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.wallpaper = view;
view.image=wallpaper;
[self.view addSubview:view];
}
-(IBAction)next:(id)sender {
self.n++; // increases n by 1;
[self.wallpaper removeFromSuperview];
NSString* name = [NSString stringWithFormat:#"wp_%i.png", self.n];
UIImage* wallpaper = [UIImage imageNamed:name];
UIImageView* view = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
self.wallpaper = view;
view.image=wallpaper;
[self.view addSubview:view];
}
something like that. hope that helps
Of course not. I would use a UITableView for that. Or even better a custom view that looks similar to the Photos app on the iphone.
You don't want to use a UIButton to go to the previous or next photo. You want to use a UIScrollView in paging mode.
But you don't want the user to browse through your images in that way in the first place.
Create a index screen that has a UIScrollView (non-paging this time) with thumbnails of all your images. And when one is tapped it zooms in with a nice animation and you can flick to the next or previous image with the paging UIScrollView I mentioned earlier.
You know, like the Photos app.
in the header (.h file) add something like that:
int n;
UIImageView* wallpaper;
}
#property (readwrite) int n;
#property (readwrite, retain) UIImageView* wallpaper;
in the implemention fil (.m file) :
#synthesize n, wallpaper;

Pros and cons of using CCUIViewWrapper versus a ported functionality

I'm trying to understand the pros and cons of using something CCUIViewWrapper in Cocos2d versus a ported functionality. For instance, would it be better to use a UITableView in a CCUIViewWrapper, or to use the CCTableViewSuite. At first glance, I would assume the wrapper is the better approach since presumably it allows me to do everything the UITableView offers, but are there key details I'm missing? Are there severe limitations that exist with the wrapper either with actually using the apple sdk object or with not being able to take advantage of certain features within Cocos2d that come with a ported object like CCTableView?
I have copied this post from here that may help answer your question. I believe that it would be better to uses cocos2d functions with cocos2d wrappers but you can implement with others it just doesn't integrate as well.
If there are any newbies (like myself) out there that need extra help how to integrate a UIKit item with cocos2d, this might help. As you have read in the first post of this thread Blue Ether has written a wrapper for manipulating UIViews. What is a UIView? Look at http://developer.apple.com/iphone/library/documentation/uikit/reference/uikit_framework/Introduction/Introduction.html, scroll down a little bit and you will see a diagram of different UIView items; things like UIButton, UISlider, UITextView, UILabel, UIAlertView, UITableView, UIWindow and so on. There are more then 20 of them. You can use Blue Ethas code to wrap any of them inside cocos2d. Here I will wrap a UIButton, but experiment with your favorite choice of UIView item.
Create a new cocos 2d Application project.
Make a new NSObject file and call it CCUIViewWrapper. That will give you the files CCUIViewWrapper.h and CCUIViewWrapper.m. Edit (by copy paste) them so they look as Blue Ether has defined them (see the first post in this thread.
Make your HelloWorld.h look like this
// HelloWorldLayer.h
#import "cocos2d.h"
#import <UIKit/UIKit.h>
#import "CCUIViewWrapper.h"
#interface HelloWorld : CCLayer
{
UIButton *button;
CCUIViewWrapper *wrapper;
}
+(id) scene;
#end
and your HelloWorld.m like this
// HelloWorldLayer.m
#import "HelloWorldScene.h"
// HelloWorld implementation
#implementation HelloWorld
+(id) scene
{
CCScene *scene = [CCScene node];
HelloWorld *layer = [HelloWorld node];
[scene addChild: layer];
return scene;
}
-(void)buttonTapped:(id)sender
{
NSLog(#"buttonTapped");
}
// create and initialize a UIView item with the wrapper
-(void)addUIViewItem
{
// create item programatically
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:#selector(buttonTapped:) forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Touch Me" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 120.0, 40.0);
// put a wrappar around it
wrapper = [CCUIViewWrapper wrapperForUIView:button];
[self addChild:wrapper];
}
-(id) init
{
if( (self=[super init] )) {
[self addUIViewItem];
// x=160=100+120/2, y=240=260-40/2
wrapper.position = ccp(100,260);
[wrapper runAction:[CCRotateTo actionWithDuration:4.5 angle:180]];
}
return self;
}
- (void) dealloc
{
[self removeChild:wrapper cleanup:true];
wrapper = nil;
[button release];
button=nil;
[super dealloc];
}
#end
Build and Run. This should produce a rotating button in the middle of the scene. You can touch the button while it rotates. It will write a text message in the Console.
CCUIViewWrapper is not a good solution. I have tried and removed it. The problem is that it wraps the UIKit element in a container and adds it as a view on director over the openGL main view. One problem with that is that you will not be able to add any other sprite on top of it. Very limited.

Resources