Jump to content


Photo

Box2D and the iOS runner


  • Please log in to reply
7 replies to this topic

#1 Mayhem Games

Mayhem Games

    Proud Kiwi

  • GMC Member
  • 955 posts
  • Version:GM:Studio

Posted 02 March 2012 - 02:31 PM

I have been playing with Box2D and Game Maker:Studio for the last hour and I finally got it to work. The demo I made works great in the C++ runner but runs REALLY slowly on iOS, even with just one falling box I get around 2FPS.

Would this be something I am doing or is the runner on iOS not fully compatible with Box2D yet?
  • 0

#2 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1415 posts
  • Version:Unknown

Posted 02 March 2012 - 02:51 PM

Must be something that you are doing as everything works at full speed here...

Russell
  • 0

#3 Mayhem Games

Mayhem Games

    Proud Kiwi

  • GMC Member
  • 955 posts
  • Version:GM:Studio

Posted 02 March 2012 - 03:20 PM

Must be something that you are doing as everything works at full speed here...

I have had a look over my code and I can't seem to see what I am doing wrong, I only have the bare minimum code for the physics to work.

I only have 4 objects. obj_Controller (For the world and spawning objects), obj_Block (The falling block), obj_Ball (Same as the block just a different sprite) and obj_Floor.

//////////////////////////////
//obj_Controller Create Code
physics_create_world(rm_Room,-16,-16,480,320,16)
physics_gravity(rm_Room,0,-8)
physics_update_speed(rm_Room,1)

for(i=0;i<=480;i+=32)
{
    instance_create(i,304,obj_Floor)
}

//////////////////////////////
//obj_Control Step Code
random = irandom(1)

if (random == 0)
{
    instance_create(mouse_x,mouse_y,obj_Block)
}
else
{
    instance_create(mouse_x,mouse_y,obj_Ball)
}
//////////////////////////////
//obj_Block Create Code
pfx = physics_create_fixture()

physics_fixture_set_box_shape(pfx,16,16)
physics_fixture_set_density(pfx,1)
physics_fixture_set_collision_group(pfx,1)

physics_bind_fixture(pfx)

//////////////////////////////
//obj_Floor Create Code
ffx = physics_create_fixture()

physics_fixture_set_box_shape(ffx,16,16)
physics_fixture_set_collision_group(ffx,1)

physics_bind_fixture(ffx)

What I don't get is that I works mint in the C++ runner. :unsure:

Edited by Mayhem Games, 02 March 2012 - 03:21 PM.

  • 0

#4 CloudBomb

CloudBomb

    GMC Member

  • GMC Member
  • 226 posts
  • Version:GM:Studio

Posted 02 March 2012 - 03:24 PM

I don't have access to my iPhone here right now but the only thing I can think of based off what you're saying is the following:

1) The negative values for the physics container may be an issue on the iOS? This might cause problems.
2) The floor loop might not be closing for some reason as it's in create code? Causing infinite lag due to placing forever? I'm reaching for this but the characteristic of your FPS lag says it's not enough to hardlock the game but enough to cause fps lag.
3) And mouse_x/mouse_y might be static, so even when your finger is off the screen it might still have that number. Causing overlays and lag.
4) Suggestion:
switch (irandom(1)) {
          case 0:
          instance_create(mouse_x, mouse_y, obj_Block);
          break;

          case 1:
          instance_create(mouse_x, mouse_y, obj_Ball);
          break;
}

I only suggest this so you don't have a variable hanging around, and I find for simple things, switch() checks are fast, neat, and clean.


*Edit* rwkay has your answer :P

Edited by CloudBomb, 02 March 2012 - 03:48 PM.

  • 0

#5 rwkay

rwkay

    YoYo Games CTO

  • YoYo Games Staff
  • 1415 posts
  • Version:Unknown

Posted 02 March 2012 - 03:46 PM

You are creating an instance every frame and they will all be on top of each other on iOS as the mouse_x and mouse_y is only updated when a finger is pressed on the screen you need to put a check to see if the left mouse button is pressed on that.

The instances will all be getting created at 0, 0 and they will be intersecting causing the physics to go mad...

Russell
  • 0

#6 Mayhem Games

Mayhem Games

    Proud Kiwi

  • GMC Member
  • 955 posts
  • Version:GM:Studio

Posted 02 March 2012 - 04:08 PM

You are creating an instance every frame

Lol, I was meant to set it to global mouse release but the time of night must be getting to me. :tongue:

I have corrected that mistake and changed my step event to the global mouse release but it still lags, I even removed that entire event and had one block spawn in the obj_Control create event instead.

Would the type of iPhone effect the proformance? I have an iPhone 4G as my test phone.

Edited by Mayhem Games, 02 March 2012 - 04:09 PM.

  • 0

#7 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 16838 posts
  • Version:GM:Studio

Posted 02 March 2012 - 04:57 PM

You should also call "physics_delete_fixture" after binding as that is a memory leak you have there. A fixture is created, defined, bound and deleted (normally) unless you wish to use the same one for multiple instances...
  • 0

#8 CloudBomb

CloudBomb

    GMC Member

  • GMC Member
  • 226 posts
  • Version:GM:Studio

Posted 02 March 2012 - 11:12 PM

At first I assumed it carried like the particle system, but this is very nice clean, I rather like it.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users