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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:40:02+00:00 2026-05-22T12:40:02+00:00

I am new to Objective-C. I am currently working on a game using Cocos2D

  • 0

I am new to Objective-C. I am currently working on a game using Cocos2D and Box2D. My problem is that when 3 objects collide together, the game crashes. Now let me describe my game in details:

In my game I have a main character standing on top of a building. Below the building there’s this the road. Enemies pass by the road at various random speeds entering the screen from right and exiting from the left. I have created the enemies as b2_kinematicBodies and set a random velocity for each of them using SetLinearVelocity(). The main character shoots the enemies. The projectile (the object being shot) is a b2_dynamicBody. When the projectile hits the enemies, both the projectile and the enemy are destroyed. During gameplay sometimes an enemy moving at a slow speed is crossed by one which is moving at a higher speed. If a projectile hits the two enemies just at the point when they are overlapping and one is about to pass the other one, the game crashes! Please help me with this.

I have detected collision using b2contactListener class.

One thing I didn’t mention before is that I am not creating the enemies as individual distinct bodies. Instead, I am creating it once and making it move and I am calling this method (which creates the enemies and makes them move) inside init as below:

[self schedule:@selector(addRightTarget) interval:2.0];
  • 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-22T12:40:03+00:00Added an answer on May 22, 2026 at 12:40 pm

    I believe the issue is that the collisions are calculated before your handler gets any calls. Meaning that when your handler gets called, the bullet has hit 2 objects. So you get 2 call-backs as shown below.

    Collision Detected: Bullet + Enemy1

    • Destroy Enemy1
    • Destroy Bullet

    Collision Detected: Bullet + Enemy2

    • Destroy Enemy2
    • Destroy Bullet [CRAAAASH!!! You just tried to delete a non-existent object]

    1st: You should not be removing anything except in your step function (as someone mentioned in another answer)

    2nd: Pick one of these:

    • Make your list/array of objects-to-delete be a ‘set’ or implemented in such a way that duplicates are avoided.
    • Check for existence of your object in the world
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Objective C and XCode, currently working on my first iPhone Game.
I am currently working on an iPhone 2.1 application. I am new to Objective
Currently, my Objective C classes use C++ objects by doing a new when the
As you can tell, I'm new to Objective-C. I currently have a Singleton working,
I'm new to Objective-C and am currently following a tutorial in a book that
I am currently new to objective c and have came across a problem while
Still new to Objective C, and I'm having some trouble that I just can't
I am new to Objective C and iPhone development. I am using CoreData on
I'm new to Objective-C and Cocoa. I've read that NSInteger and NSNumber are preferred
I'm fairly new to Objective-C and wondering if it's possible to type objects as

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.