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

  • Home
  • SEARCH
  • 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 4016004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:41:15+00:00 2026-05-20T09:41:15+00:00

I have a game that I wrote. I am about ready to call it

  • 0

I have a game that I wrote. I am about ready to call it finished but I found a bug. Basically the game gets slower as the longer you play. My guess is this is due to sprites that are still being drawn off screen. I will paste the code below but basically the sprite is created in the “addNewBall” method. In this method it is added to an array which calculates its motion. After the ball reaches a position where it is off the screen it is removed from the array which causes it to stop moving but it is still being “drawn” off screen. How do I remove the sprite so the processor no longer calculates it. Thanks in advance for your help!

Tanner

Code:

-(void) addNewBall {
    NumberOfBalls = NumberOfBalls + 1;  

    int RandomXPosition = (arc4random() % 240) + 40;
    NSString *BallFileString = @"OrangeBall.png";

    switch (arc4random() % 5) {
        case 1:
            BallFileString = @"OrangeBall.png";
            break;
            case 2:
                BallFileString = @"GreenBall.png";
                break;
            case 3:
                BallFileString = @"YellowBall.png";
                break;
            case 4:
                BallFileString = @"PinkBall.png";
                break;
            case 0:
                BallFileString = @"BlueBall.png";
                break;
    }


    Ball = [CCSprite spriteWithFile:BallFileString];
    Ball.position = ccp(RandomXPosition, 520);

    BallIsMoving = YES;
    [self addChild:Ball z:10];
    [AllObjectsArray_ addObject:Ball];
    [BallArray_ addObject:Ball];

}


//And here is where it is removed...


if (Ball.position.y <= -100) {

[BallArray_ removeObject: Ball];
}
  • 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-20T09:41:15+00:00Added an answer on May 20, 2026 at 9:41 am

    You seem to be missing some conditions in your removal method. Don’t you also want to remove the ball if its y position is greater than the screen height, or if its x position is off-screen? At any rate, in the same place that you’re removing the ball from the array, you should add:

    [self removeChild:Ball cleanup: YES]
    

    I should also point out that your BallArray is probably redundant, since you’re adding all the balls to another node anyway. If the only children of that node are Balls, you can get the array of balls using its children property. In this case, the child array would be: self.children (See http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_node.html#a5e739ecda0c314283a89ac389dfca2fa for more info.)

    If you have non-Ball children on the same node, you might want to add an intermediate node to simplify the design so that you can use one less array.

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

Sidebar

Related Questions

We have a game that is very close to being released, but we have
I have a game that currently runs under Windows and Mac OS X and
I have a game engine that uses OpenGL for display. I coded a small
I have a chess game that originally used an stl list to store the
I have a game server that spawns a thread for each client with forkIO.
I have a cocos2d powered game that uses UIKit menues, so I only use
I have a big 3d game that lets players build and create interesting and
We have an existing game app that is now defunct and is just sitting
I have a facebook game application that is released at facebook platform at the
I have a C# game program that i'm developing. it uses sound samples and

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.