Hey guys, I am new here! I am 18, and just started making games for iPhone with 2 years of java under my belt! Cocos2d is really great, and has helped me learn about about making iPhone games! I have a error >_> .Don't flame me! I read before making this post and searched! Basically I have the menu for my game working, and now I am trying to do an introduction scene via a "slideshow". I am basically putting up images, and as soon as the image is touched, the next image is shown(or at least thats what the tutorial is trying to show me!). I am using the tutorial from
http://lethain.com/entry/2008/oct/29/creating-slideshows-with-cocos2d-iphone/
So, I have one small error that I have no clue what it means!
Here is my code.
#import "SimpleGameAppDelegate.h"
#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import "MenuScene.h"
#import "IntroScene.h"
#import "GameScene.h"
@implementation SimpleGameAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
[[Director sharedDirector] setLandscape: YES];
[[Director sharedDirector] attachInWindow:window];
[window makeKeyAndVisible];
IntroScene * intro = [IntroScene node];
// Initialize scene and slide show layer.
IntroLayer *layer1 = [IntroLayer node];
// Set positions for the background.
// Generally you'll be using full screen backgrounds
// (screenshots), and positioning them at the center.
[layer1 setBackgroundXPosition:100];
[layer1 setBackgroundYPosition:100];;
// Add slides in order they appear.
[layer1 addSlideWithBackground:@"pic1.png"];
[layer1 addSlideWithBackground:@"pic2.png"];
[layer1 addSlideWithBackground:@"pic3.png"];
[layer1 addSlideWithBackground:@"pic4.png"];
[layer1 addSlideWithBackground:@"pic5.png"];
[layer1 addSlideWithBackground:@"pic6.png"];
// Start and display the slide show.
[layer1 displayFirstSlide];
[IntroScene add:layer1];
[[Director sharedDirector] pushScene:intro];
//[[Director sharedDirector] runWithScene:intro];
}
IntroScene.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "CocosNode.h"
#import "Layer.h"
#import "Label.h"
#import "Sprite.h"
@interface IntroScene : Scene {}
@end
@interface IntroLayer : Layer {
int slidePosition;
int backgroundXPosition;
int backgroundYPosition;
NSMutableArray * backgrounds;
Sprite * background;
}
/*
* This is the only method for adding slides to the slide show.
*/
-(void)addSlideWithBackground: (NSString *)imageString;
/*
* Methods for advancing, retreating, and starting the slideshow.
* There currently isn't a UI mechanism for retreating to already
* seen slides, but you could rig something up if you tried hard
* enough. ;)
*/
-(void)displayFirstSlide;
-(void)displayNextSlide;
-(void)displayPreviousSlide;
-(void)displaySlide: (int)slideNumber;
-(BOOL)hasPreviousSlide;
-(BOOL)hasNextSlide;
/*
* Mutators and Accessors
*/
-(NSMutableArray *)backgrounds;
-(Sprite *)background;
-(void)setBackground: (Sprite *)aSprite;
-(int)slidePosition;
-(void)setSlidePosition: (int)anInt;
-(int)backgroundXPosition;
-(void)setBackgroundXPosition: (int)anInt;
-(int)backgroundYPosition;
-(void)setBackgroundYPosition: (int)anInt;
@end
IntroScene.m
#import "SimpleGameAppDelegate.h"
#import <UIKit/UIKit.h>
#import "cocos2d.h"
#import "MenuScene.h"
#import "IntroScene.h"
#import "GameScene.h"
@implementation IntroScene
- (id) init {/*
self = [super init];
if (self != nil) {
Sprite * bg = [Sprite spriteWithFile:@"pic1.png"];
[bg setPosition:ccp(240, 160)];
[self addChild:bg z:0];
[self addChild:[IntroLayer node] z:1];
}
return self;*/
}
@end
@implementation IntroLayer
- (id) init {
self = [super init];
if (self != nil ) {
isTouchEnabled = YES;
slidePosition = -1;
backgrounds = [[NSMutableArray alloc] init];
/*[MenuItemFont setFontSize:20];
[MenuItemFont setFontName:@"Helvetica"];
MenuItem *skip = [MenuItemFont itemFromString:@"Help" target:self selector:@selector(skip:)];
Menu *menu = [Menu menuWithItems:skip, nil];
[menu alignItemsVertically];
[self addChild:menu];*/
}
return self;
}
/*-(void)skip: (id)sender {
MenuScene *gs = [MenuScene node];
[[Director sharedDirector] replaceScene:gs];
}*/
- (void) dealloc {
[backgrounds release];
backgrounds = nil;
[background release];
background = nil;
[super dealloc];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
/*
* We are using pushScene/popScene instead of replaceScene
* (which has superior memory usage characteristics), because
* it makes integrating SlideShowLayer much simpler, and helps
* avoid binding the code to one application without requiring
* us to use the delegate pattern.
*/
if ([self hasNextSlide]) [self displayNextSlide];
else [[Director sharedDirector] popScene];
}
-(void)addSlideWithBackground: (NSString *)imageString{
[[self backgrounds] addObject:imageString];
}
-(void)displayFirstSlide {
if ([[self backgrounds] count] > 0) {
[self setSlidePosition:0];
[self displaySlide:[self slidePosition]];
}
}
-(void)displayNextSlide {
if ([self hasNextSlide]) {
[self setSlidePosition:[self slidePosition]+1];
[self displaySlide:[self slidePosition]];
}
}
-(void)displayPreviousSlide {
if ([self hasPreviousSlide]) {
[self setSlidePosition:[self slidePosition]-1];
[self displaySlide:[self slidePosition]];
}
}
-(void)displaySlide: (int)slideNumber {
/*
* Remove existing slide and description.
*/
if ([self background]) {
[self remove:[self background]];
}
/*
* Retrieve and generate necessary details for next slide.
*/
NSString * bgString = [[self backgrounds] objectAtIndex:slideNumber];
Sprite * bg = [Sprite spriteWithFile:bgString];
bg.position = cpv([self backgroundXPosition], [self backgroundYPosition]);
// Add the background and desc to the layer.
[self setBackground:bg];
[self add:bg];
}
-(BOOL)hasNextSlide {
return ([self slidePosition]+1 < [[self backgrounds] count]);
}
-(BOOL)hasPreviousSlide {
return ([self slidePosition] > 0);
}
-(Sprite *)background {
return background;
}
-(void)setBackground: (Sprite *)aSprite {
if (background) [background release];
background = [aSprite retain];
}
-(NSMutableArray *)backgrounds {
return backgrounds;
}
-(int)slidePosition {
return slidePosition;
}
-(void)setSlidePosition: (int)anInt {
slidePosition = anInt;
}
-(int)backgroundXPosition {
return backgroundXPosition;
}
-(void)setBackgroundXPosition: (int)anInt {
backgroundXPosition = anInt;
}
-(int)backgroundYPosition {
return backgroundYPosition;
}
-(void)setBackgroundYPosition: (int)anInt {
backgroundYPosition = anInt;
}
@end
The error I get is from introScene.m in the displaySlide method
NSString * bgString = [[self backgrounds] objectAtIndex:slideNumber];
Sprite * bg = [Sprite spriteWithFile:bgString];
bg.position = cpv([self backgroundXPosition], [self backgroundYPosition]);
On the last line, I get error:incompatible type for first position!
I tried changing things, but it is not working! Please help! Thanks! Once again, sorry if my code is miserable and lousy. I am just learning ._.!