views:

161

answers:

1

I am developing some games using multi touch for iPhone (cocos). Could anyone teach me how to start, from very scratch beginning. I am not sure where to start or any resources that can help. I really appreciate the helps.

@implementation GameScene

- (id)init
{
    if (self = [super init])
    {
     Sprite *background = [Sprite spriteWithFile:@"unzip.png"];

     background.position = CGPointMake(240,160);
     [self addChild:background];

     Label *aboutContent = [Label labelWithString:@"Welcome to the game" fontName:@"Helvetica" fontSize:30];
     aboutContent.position = CGPointMake(240,160);
     [self addChild:aboutContent];
    }
    return self;
}
@end

I have this code. This import the image . The just want the players can touch 2 points A and B in the centre and move them in the opposite sides far from each other. Could anyone give me some examples.?

+2  A: 

Monocle Studios has a whitepaper: introduction to cocos2d iphone. Pretty good place to start from.

Touches can be detected by any Layer by settings isTouchEnabled property to YES.

Any other CocosNode class descendant can implement the protocol TargetedTouchDelegate and StandardTouchDelegate and then register itself with the touch dispatcher:

[[TouchDispatcher sharedDispatcher] addTargetedDelegate:self
                                    priority: 0 swallowsTouches:YES];

You must then implement:

  • - (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
  • - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
  • - (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event

in that object.

Hope that helps.

nash