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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:38:11+00:00 2026-05-30T00:38:11+00:00

In my test game i have some sprites ( Bubbles = NSMutableArray) wich are

  • 0

In my test game i have some sprites (Bubbles = NSMutableArray) wich are appear in random location at bottom of the screen.

I have addBubble and spawBubble methods:

- (void) addBubble {

CGSize winSize = [[CCDirector sharedDirector] winSize]; 
bubbles = [[NSMutableArray alloc] init];

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"bubbleSpriteList.plist"];
CCSpriteBatchNode *bubbleSpriteList = [CCSpriteBatchNode batchNodeWithFile:@"bubbleSpriteList.png"];
[self addChild:bubbleSpriteList];



bigBubble = [CCSprite spriteWithSpriteFrameName:@"bubble"];
[self addChild:bigBubble];
[bubbles addObject:bigBubble];


for (CCSprite *bubble in bubbles) {


    int minX = bubble.contentSize.width/2;
    int maxX = winSize.width-bubble.contentSize.width/2;
    int rangeX = maxX - minX;
    int actualX = (arc4random() % rangeX) + minX;
    bubble.position = ccp(actualX, 0);


    int minSpeed = 15.0;
    int maxSpeed = 20.0;
    int rangeSpeed = maxSpeed - minSpeed;
    int actualSpeed = (arc4random() % rangeSpeed) + minSpeed;


    ccBezierConfig bubblePath;
    bubblePath.controlPoint_1 = ccp(200, winSize.height/3);
    bubblePath.controlPoint_2 = ccp(-200, winSize.height/1.5);
    bubblePath.endPosition = ccp(0, winSize.height+bubble.contentSize.height/2);
    id bezierMove = [CCBezierBy actionWithDuration:actualSpeed bezier:bubblePath];

    [bubble runAction:bezierMove]; 
}}
-(void)spawBubble:(ccTime)dt {
[self addBubble];}

Then in my init method i added background and spawBubble method with random time interval

[self schedule:@selector(spawBubble:) interval:actualTime];

I’m trying to make every bubble from Bubbles blow, when it was touched, with this code

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];

for (CCSprite *bubble in bubbles) {
CGRect bubbleRect = CGRectMake(bubble.position.x - (bubble.contentSize.width/2), 
                                   bubble.position.y - (bubble.contentSize.height/2), 
                                   bubble.contentSize.width, 
                                   bubble.contentSize.height);
    if (CGRectContainsPoint(bubbleRect, touchLocation)) {            
        NSLog(@"%i", [bubbles count]);
        [bubble setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"bubbleBlow"]];
        id disappear = [CCFadeTo actionWithDuration:0.1 opacity:0];
        [bubble runAction:disappear];            
    }
}

return TRUE;}

Every bubbles blowing perfectly if only one bubble in the screen, but if one bubble on the screen and another one was appeared, only last one is detects touches.

What am i doing wrong?

  • 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-30T00:38:13+00:00Added an answer on May 30, 2026 at 12:38 am

    Hard to tell without seeing more code – but here’s where I’d start:

    Above this line:

    for (CCSprite *bubble in bubbles) {

    add:

    NSLog(@"%i", [bubbles count]);

    EDIT:

    Based on the code you added:

    Your problem is with this line:

    bubbles = [[NSMutableArray alloc] init];

    which is effectively wiping out your bubbles array every time you add a new bubble.

    So, there will only ever be one bubble in the array – the last one.

    Hence the problem you’re running into.

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

Sidebar

Related Questions

I'm writing code for a blackjack game and have run into some problems. I
Im trying to create a NSThread game loop, i have some of the time
I have been using C# for some time now to make a small game,
I'm trying to write a game engine in Android, but I don't have much
I've been trying to make a little simple game just to test my logics,
I have written a game (I'll give it the name Gamer) in which I
I want to use redis for my game's leaderboard data and I have seen
So, I'm starting to write some logic for a simple program (toy game on
Ahoy! I've been looking into updating some old test code in an attempt to
I'm working on a state based game engine and have something I'm happy with

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.