Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6573843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:11:05+00:00 2026-05-25T15:11:05+00:00

This question is too primitive, but I have been trying for the last 8

  • 0

This question is too primitive, but I have been trying for the last 8 hours, and it is eating away my energy ( and confidence levels too :))

In my class, I have registered for Targeted touches.

  [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];

I would like to check if the user is performing single tap or double tap. In ccTouchBegan method, first gets a touch with singleTap, then gets a touch with doubleTap. I found a very interesting solution for this one, in one of the Cocos2d Forums. ( I could not locate it now.. )

The solution goes like this.

switch (touch.tapCount) {
            case 2:
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(handleSingleTouch:)  object:singleTouchLocation];
             // Handle Double Touch here
                break;
            case 1:


                self.singleTapLocation = ccp(location.x,location.y);
                self.singleTouchLocation = touch;

                [self performSelector:@selector(handleSingleTouch:) withObject:touch afterDelay:0.3
             ];



                break;
        }

Everything looks to be working fine. Essentially, you schedule a single touch handler with a delay and see if it is actually a double tap. If it is a double tap, then cancel singletap handler and perform logic for double tap.

But my problem is, In the single touch handler (handleSingleTouch), I am adding a CCSprite to the UI. This action is not working. No sprite gets added. (Although the method is called.). In fact this works, If I call the selector with no delay, but with delay, the sprite is not added.

I am not a Objective C expert, So, I apologize if the question is too primitive.

Edit 1: The original thread.

Edit 2: Posting handleSingleTouch.. only relevant code.

-(void) handleSingleTouch:(UITouch * ) touch  {

    CGPoint location = [touch locationInView: [touch view]];
    CGPoint glLocation = [MainSceneLayer locationFromTouch:touch];
    //Single tap
    CCLOG(@"Single tap: Adding marker image");


    if(zoomedOut) {

        CGPoint globalCoordinates = [quadConvertor convertLocalToGlobal:location 
                                                       inActiveQuadrant:activeQuadrant];



        if( [self isTouchValidForSelectedItem:globalCoordinates] == Matched) {
            [self addMarkerImages:glLocation];
        } else if([self isTouchValidForSelectedItem:globalCoordinates] == NotMatched) {
            [missedLabel stopAllActions];

            for (ImageQuadrants* quad in quadrants) { 
                if(quad.quadrantNumber == activeQuadrant) {

                    missedLabel.position  =  ccp((quad.center.x * -1)+glLocation.x  , (quad.center.y * -1)+glLocation.y);

                    //markers.position =  ccp((quad.center.x * -1)+touchPosition.x  , 320);


                }

            }


            id blinkAction = [CCBlink actionWithDuration:1 blinks:3];
            id makeInvible = [CCCallFunc actionWithTarget:self selector:@selector(makeInvisible:)];



            id seq = [CCSequence actions:blinkAction, makeInvible,  nil];

            [missedLabel runAction:seq];

        } else {

            [alreadyAccountedLabel stopAllActions];

            for (ImageQuadrants* quad in quadrants) { 
                if(quad.quadrantNumber == activeQuadrant) {

                    alreadyAccountedLabel.position  =  ccp((quad.center.x * -1)+glLocation.x  , (quad.center.y * -1)+glLocation.y);

                    //markers.position =  ccp((quad.center.x * -1)+touchPosition.x  , 320);


                }

            }


            id blinkAction = [CCBlink actionWithDuration:1 blinks:3];
            id makeInvible = [CCCallFunc actionWithTarget:self selector:@selector(makeInvisible1:)];



            id seq = [CCSequence actions:blinkAction, makeInvible,  nil];

            [alreadyAccountedLabel runAction:seq];


        }

    }


    swipeStartPoint = [touch locationInView:touch.view];


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:11:05+00:00Added an answer on May 25, 2026 at 3:11 pm

    i dont know if thats a typo in your question only but your delay method is all wrong. There is no withDelay: argument. it should look like this:

    [self performSelector:@selector(handleSingleTouch:) withObject:touch afterDelay:0.1];
    

    EDIT:

    Since your problem is most probably with the touch getting lost. Try [touch retain] before calling the delayed method. Another way is changing the handleSingleTouch: method to take two floats x and y or a CCPoint as arguments instead of a UITouch. Then you create the floats before the delayed method and pass them in the delayed method. This way you will avoid a memory leak from retaining a touch as well since most probably you cant release it after calling the delayed method.

    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this question is too vague, but I'd rather not muddy it's point
This question may be too product specifc but I'd like to know if anyone
I hope this question isn't too open ended, but a nudge in the right
The code for this question is too long to be of any use. But
This question is specific to capistrano, but it's a general gem question too. I
This question sounds too trivial, but I could not find the answer anywhere. I
I was asked this question not too long ago, and didn't have a good
Good afternoon, I'm sorry if this question is too silly, but I don't know
I'm new to SSRS, so I apologize if this question is too simple: I
This question may sound too silly, however , I don't find concrete answer any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.