Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Can't figure out touch events to save my life..
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
dnite  
View profile  
 More options Jan 4, 12:27 am
From: dnite <TehDN...@gmail.com>
Date: Sat, 3 Jan 2009 21:27:12 -0800 (PST)
Local: Sun, Jan 4 2009 12:27 am
Subject: Can't figure out touch events to save my life..
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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Codemattic  
View profile  
 More options Jan 6, 7:59 am
From: Codemattic <codemat...@gmail.com>
Date: Tue, 6 Jan 2009 04:59:01 -0800 (PST)
Local: Tues, Jan 6 2009 7:59 am
Subject: Re: Can't figure out touch events to save my life..
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:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Codemattic  
View profile  
 More options Jan 6, 8:03 am
From: Codemattic <codemat...@gmail.com>
Date: Tue, 6 Jan 2009 05:03:22 -0800 (PST)
Local: Tues, Jan 6 2009 8:03 am
Subject: Re: Can't figure out touch events to save my life..
also define it as:

- (BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

with a return type of BOOL and not void

On Jan 6, 7:59 am, Codemattic <codemat...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dnite  
View profile  
 More options Jan 6, 2:36 pm
From: dnite <tehdn...@gmail.com>
Date: Tue, 6 Jan 2009 13:36:14 -0600
Local: Tues, Jan 6 2009 2:36 pm
Subject: Re: [cocos2d-iphone] Re: Can't figure out touch events to save my life..

I tried adding that return too.. I just figured it out.. Still not sure what
was clogging it.. But I added the following to the main loop in cocos2d's
director and it seems to have worked.. it was the solution I found on the
blog and a couple other places.. Anyone know 'why' this works and/or what's
preventing cocos2d from working correctly without it?

while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES) ==
kCFRunLoopRunHandledSource) {};


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google