On Tue, Jan 6, 2009 at 6:59 AM, Codemattic <codemat
...@gmail.com> wrote:
> in -ccTouchesBegan: you should probably return kEventHandled (or
> kEventIgnored if you dont want to handle that event)
> Im not sure that is what is throwing your code off, but try that.
> On Jan 4, 12:27 am, dnite <TehDN...@gmail.com> wrote:
> > I'm new to objective-c and cocoa and am having trouble getting this to
> > work. I'm trying to start simple but the simplest thing just isn't
> > working for me.. i'm using cocos-iphone 0.6.2 ... This is just about
> > all that I have right now and it works fine in the simulator, but the
> > iphone chokes after a couple of touches.. if I hit the home button on
> > the iphone, all the queued touches fly across the log.. What am I
> > missing?
> > Enemy.m
> > =================================
> > @implementation KeithHead
> > // implimentation of rect for touch detection
> > - (CGRect) rect {
> > float w = [self contentSize].width;
> > float h = [self contentSize].height;
> > CGPoint point = CGPointMake([self position].x - (w/2), [self
> > position].y + (h/2));
> > point = [[Director sharedDirector] convertCoordinate:point];
> > return CGRectMake(point.x, point.y, w, h);
> > }
> > - (id) init {
> > self = [super init];
> > if (self != nil) {
> > // Set the size of the enemy image (in case it changes
> later)
> > int enemy_width = 100, enemy_height = 159;
> > int max_width = 320 - enemy_width, max_height = 470 -
> enemy_height;
> > // init self w/ enemy.png
> > [self initWithFile:@"enemy.png"];
> > // Set it's position to a random spot
> > int x = (arc4random() % max_width) + (enemy_width / 2);
> > int y = (arc4random() % max_height) + (enemy_height /2);
> > [self setPosition:cpv(x,y)];
> > }
> > return self;
> > }
> > @end
> > GameScene.m
> > ===============================================
> > @implementation GameScene
> > - (id) init {
> > self = [super init];
> > if (self != nil) {
> > // Create a sprite for the background
> > Sprite *background = [Sprite
> > spriteWithFile:@"background_gradient.png"];
> > // Position and add it to the bottom z-index
> > [background setPosition:cpv(160, 240)];
> > [self add:background z:0];
> > // Add the game layer just above the background
> > [self add:[GameLayer node] z:1];
> > }
> > return self;
> > }
> > @end
> > @implementation GameLayer
> > - (id) init {
> > self = [super init];
> > if (self != nil) {
> > isTouchEnabled = YES;
> > }
> > return self;
> > }
> > - (void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
> > NSLog(@"Touched!");
> > }
> > @end