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 7893625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:10:49+00:00 2026-06-03T07:10:49+00:00

I have touches ended implemented for a CCLayer in cocos2D. When a touch is

  • 0

I have touches ended implemented for a CCLayer in cocos2D.
When a touch is received, it calls a method.. however, calling the method seems to always result in the app crashing due to “EXC_BAD_ACCESS”
In the method that I call, I try to read from a NSMutableDictionary
Here’s my code:

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchPoint = [touch locationInView:[touch view]];
    touchPoint = [[CCDirector sharedDirector] convertToGL:touchPoint];
    int current = 1;
    int i = 1;
    for (i=1; i<=4; i++) {
        CCNode *sprite = [layer2 getChildByTag:i];
        CGPoint worldCoord = [layer2 convertToWorldSpace:sprite.position];
        CGRect bounds = CGRectMake(worldCoord.x-sprite.boundingBox.size.width, worldCoord.y-sprite.boundingBox.size.height/2, sprite.boundingBox.size.width, sprite.boundingBox.size.height);
        //CCLOG(@"Sprite%i:%f,%f at %f,%f",i,bounds.size.width,bounds.size.height,bounds.origin.x,bounds.origin.y);
        if (CGRectContainsPoint(bounds, touchPoint)) {
            CCLOG(@"touched sprite:%i",i);
            current = i;
            [self checkSpriteTouch:current]; //error occurs when this method is called

            break;
        }
    }
}
-(void)registerWithTouchDispatcher{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:1 swallowsTouches:NO];
}


-(void)checkSpriteTouch:(int)i{
    NSMutableDictionary *dict = [storeDict objectForKey:[NSString stringWithFormat:@"Char%i",1]]; //when using debugging, app crashes here at this line
    NSNumber *boughtValue = [dict objectForKey:@"Bought"];
}

Why does my application crash? All other methods which I implement in my other touchEnded methods work perfectly fine…
Thank you in advance! Any help is GREATLY appreciated ^_^

  • 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-06-03T07:10:50+00:00Added an answer on June 3, 2026 at 7:10 am

    I finally figured out why accessing that method would cause my app to crash.
    The answer was in accessing the Dictionary.
    I had not retained it properly, thus causing the bad access warnings.
    To fix it, in the header file, I used:
    @property(nonatomic,retain)NSMutableDictionary *storeDict;
    and now, everything works fine! ^_^

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

Sidebar

Related Questions

I have subclassed a UIImageView, and have implemented touchesBegan/Moved/Finished like this: - (void)touchesBegan:(NSSet *)touches
I have two sprites in my app. Both should have touches enabled and both
I have created a subclass of UIImageView and I am handling the touches for
I have a view controller and I am intercepting the touches on links within
I have an application that starts playing a sound when user touches the uiview
I have to draw a circle in live wallpaper when it touches the boundary
So I have a Subclass of UIView that is suppose to detect touches. The
I have a sprite and if it is touched the touch should be recognized.
I have a text in my game which is written in cocos2d. The text
Setup: I have two views that I need to respond to the touch event,

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.