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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:42:34+00:00 2026-05-28T15:42:34+00:00

In the box2d physics loop of my game (the step), I must call the

  • 0

In the box2d physics loop of my game (the step), I must call the following block:

if ([objectA conformsToProtocol:@protocol(FMCollisionProtocol)]) {
    [objectA performSelector:@selector(collideWith:) withObject:objectB];
}
if ([objectB conformsToProtocol:@protocol(FMCollisionProtocol)]) {
    [objectB performSelector:@selector(collideWith:) withObject:objectA];
}

The problem is that collideWith: may alter my physics object and this isn’t allowed during the step. Once the step is finished, the physics objects are free to be altered once more. I need some way to remember the target, selector and object paramater of this block for later use. One option would be to use a struct like this:

typedef struct {
    id target;
    SEL selector;
    id object;
} FMCallback;

And store these in an array. Once I’ve finished my step, I then analyse this array and call performSelector:. Is there a better way around this?

EDIT:

I tried both ways and found blocks to be simpler. I’m using a protocol, so I was unsure how to handle this (it would always return a nil NSMethodSignature):

NSMethodSignature *sig = [FMObject instanceMethodSignatureForSelector:@selector(collideWith:)];
NSInvocation *invoc = [NSInvocation invocationWithMethodSignature:sig];
invoc.target = objectB;
invoc.selector = @selector(collideWith:);
[invoc setArgument:objectA atIndex:2];
[Presenter.physics.callbacks addObject:invoc];

It was also longer than I would have hoped. The blocks worked fine after some reading:

// In the collision
[Presenter.physics.callbacks addObject: Block_copy(^{
    [(id)objectB collideWith:objectA];
})];

// After the step
for (id collision in callbacks_) {
    ((dispatch_block_t)collision)();
    Block_release(collision);
}
[callbacks_ removeAllObjects];
  • 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-28T15:42:35+00:00Added an answer on May 28, 2026 at 3:42 pm

    How about blocks?

    NSMutableArray *collisions = [NSMutableArray array];
    …
    [collisions addObject:^{
        [objectA collideWith:objectB];
    }];
    …
    for (id collision in collisions)
        ((dispatch_block_t)collision)();
    

    This is with ARC; without ARC you should probably add a copy and autorelease when adding the blocks to the array.

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

Sidebar

Related Questions

Salut, I'm currently working on a pool game in flash, using box2d for physics
I'm developing a physics game using AndEngine with box2d physics engine. I have a
Currently I am using the Box2D physics engine in a game of mine -
I am creating game with box2d physics, I have a crane with rope attached
I've been making a game which uses the Box2D physics engine, and I've come
I am making a game using Andengine/Box2D physics addon. I experienced the random crashes
I'm using Box2d for a Bike Physics Game, Box2d lets you have fixtures that
I'm using Cocos2D and Box2D for a game with some physics. There's an occasional
I have some code that causes the box2d physics simulation to stutter forever after
I am not sure if many of you are familiar with the box2d physics

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.