Problem on physics.addBody with generated collision shape object

Hi again,

I’m looking to my logs on testFairy and i’ve notice a error that throw many times at the beginning of level and stopped after a while. With this message 

physics.addBody() of a “shape” with no area, or nearly no area, has been rejected.

 

The line that the error are indicate is where i add the generated collision shape object i’ve using software Physics Editor for create that object. What i think is interesting that error not affect my game physics i mean the game go normal with all collision and reaction they should have. I’ll leave on the attachment a print screen of my game scene with draw mode to hybrid.

 

The line of code that are throwing the error is for a circle :

 

physics.addBody( circle, “static”, physicsData:get(“circle-incomplete”) )

 

 

What I can do to solve this? I already test some scenario like pause physic but the error are throw anyway.

 

Thanks in advance 

 

 

 

 

So, you’re saying, You get the error, but you’re 100% certain the body is produced and works anyways?  That would be annoying although not deadly to your game.

What resolution are you working at?

Consider, if it is not too late, working at a higher design resolution, then you can make all of the bodies bigger.

i.e. If you’re config.lua is small 320x480, change to 640x960, then double the size of your shapes, and generated bodies.  

You may simply be running into an issue with precision and increasing the size of the world (design space) will help this.

Hopefully i’m being clear here.

Yes that is what happens, I see a lot of this error for a while after some time that error stop to be throwing. My resolution is from nexus 5 its means 1080 x 1920 pixels

Also I’ve more question, i would like some advises on there.

  1. First I want move a object during a collision i known that is impossible so i just create to object and just change the visible of them that disappear  of screen but physical body remains active, that is right? It’s possible to hide or disable physical interaction too?

  2. Second I’ve on object that i like to be on screen and have a physical behavior to detect collision but i’m not want this object have any reaction on collision like bounce and friction to do that i’ve use preCollision event to detect colission and I’ve set contact to false : event.contact.isEnabled = false that is the right think to do? 

Or i’ve other way to do this I notice that my device are spending much battery I fear that is because of preCollision event

Thanks in advance  

So, your config.lua settings are 1080x1920? Just double checking.

 

  • You can move an object just after a collision.  Simply wait one frame:

    timer.performWithDelay( 1, – 1 ms delay becomes one frame (delay > 0 and < ‘frame period’ == one frame wait) function() – move code here end )

  • You can effectively disable bodies and you can remove bodies, but not until after the collision is done processing (performWithDelay() again)

My config is this : 

content =
    {
        width = 0,
height = 0,
        scale = “letterBox”,
        fps = 60,

I’ve just run on a simulator with nexus 5 resolution, I want to use always the full screen of device.

Your performWithDelay is in pseudo code or i can use this piece of code, because i never find any documentation to able to do this. 

Can for all your quick response its will help me a lot.

Thanks in advance 

First, You’re welcome,
 
 
Second, no that wasn’t pseudo code (except that the comment was where you put your code):

Here is a more complete collision example with performWithDelay():

local function onCollision( self, event ) if( event.phase == "began" ) then -- Do something next frame to avoid physics violations timer.performWithDelay( 1, function() -- Do your 'something here' i.e. Write lua code to do work end ) end return true end

Third,
Again, I want to stress that I think that using auto- selected or calculated config.lua width/height is an extremely bad idea.  
 
You’re asking for an ambiguous work environment rife with questions, trouble, and surprises.  Basically what you’re encountering now.  
 
In my mind, the real purpose of config.lua is to create a known working environment.  Some seem to think, they can make a fixed design (their code) and somehow add code to config.lua to magically make their design fit.  This is upside-down thinking.
 
Sorry if I sound impassioned here. But I see this kind of misunderstanding and backwards thinking a lot and it’s hard to help folks after they’ve made a bad decision and decided it was the right one. :slight_smile:
 
My (not so humble opinion) is that you are best served by designing in this fashion:

** NOTE: My list below got corrupted and I’m not going to take time to correct it.  Sorry if this a a little confusing. **

  • Select a single base resolution that matches your primary market/device and encode that in config.lua.  A good choice is the iPhone 5.  It scales nicely up to iPhone 6 and the numbers are still small enough to do calculations on in your head when writing code.

  • Pre-calculate helpers as a module or globals (like I do) for such things as

    • w, h, fullw, fullh
    • left, right, top, bottom
    • unusedWidth/unusedHeight - Extra pixels on the current device. I use these less often now that I have left, right, … defined.
  • Adjust your app design to account for cases when you need to fill unused space and/or move elements to the edges of the screen.

  • Test, test, test.

  • Once you’ve mastered this approach, you’ll be better able to make alternate choices in config.lua.  However, starting from a completely undefined starting point will make life painful.  Again, my (not so) humble opinion.
     
    -Ed Out!

Hi again,
 
First I would like to thanks for your help I’m glad to learn with your ideas!
 
About my errors most of them already solved (thanks to you) I’ve remove my preCollision event and also I’ve solve my error when addBody() is called for this I’ve draw new pic and use again the physical editor to add again on my code. 
 
About auto selected or calculated config.lua width/height  you probably right I’ve been fighting  this since the beginning of my project, I try to follow your tips and have only on dev environment.

I think I’ve understand what you said create a global file where store variables that define the environment, however i’m not sure how I can get extra pixeis for a device that i’ve more that my definition for exemple for ipad mini have that screen on my game 

Even I’ve this 

https://drive.google.com/open?id=0BwJSv-5D6Hb2V1podjJERXBvTGM (see the pic)

local screenW, screenH = display.contentWidth, display.contentHeight

local background = display.newRect( 0, 0, screenW, screenH )

My backgroud dont use all of device screen but for example I use Admob to monetize and their banner are started at more left side of my screen, my doubt is how to get that extra pixels? To use them and make my code compensation like you suggest extra width and height 

Sorry to bore your with all of my questions

Hi.  Sorry, I’m having some trouble knowing what you’re asking, but I’ll give it a go:

1.You showed an image where the background was not covering all of the screen.  Make your images bigger so they cover the worst case screen size using your config.  Just make sure the most important part shows on your ‘target resolution’.  Then the extra width and height are for viewing on other sized devices.

Download this project, then run it with the various simulated devices ( iPad, iPhone5, Nook, etc. ) to see what I mean.  Then take a look at the image I used for the background.  See how it is extra wide and tall?  The pink part is extra for off-sized devices.

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/08/moreconfig.zip 

  1. Download this project and run it: 

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/08/config.zip

 

Notice how I calculate left, right, top, bottom etc?  I use these to handle cases where I want to align to the edges.  I also calculate unusedWidth and unusedHeight.  If these are non zero, I have extra pixels in that dimension.

 

 

  1. Finally look at this admob sample to see how to get your ads to align properly at the top of bottom and fill the whole width.

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/06/admob.zip

Hi,

Thank for your reply again.

I’ve look to your sample and that awesome I just not know about display.actualContentWidth and display.actualContentHeight with that know i can scale my screen background to all width height of device.

What I’ve done is follow or tips and force a environment with some resolution for calculate all the movable objects that interact on game engine, my is only move object on Y axis. So I’ve compensate all background with that extra pixes to scale the image to full screen.

By the away I would like to ask one more question, for splash screen for example i’ve and image with 1080x1920 that is perfect for my forcing resolution, for device with low resolution them that is okay, however for much big screen with retina display what I’ve done for now is loading a high resolution picture by checking a device resolution with a if checking is more and 1080x1920 is there a way for doing that automaticly without if’s??

Thanks one more time you’re help me alot

So, you’re saying, You get the error, but you’re 100% certain the body is produced and works anyways?  That would be annoying although not deadly to your game.

What resolution are you working at?

Consider, if it is not too late, working at a higher design resolution, then you can make all of the bodies bigger.

i.e. If you’re config.lua is small 320x480, change to 640x960, then double the size of your shapes, and generated bodies.  

You may simply be running into an issue with precision and increasing the size of the world (design space) will help this.

Hopefully i’m being clear here.

Yes that is what happens, I see a lot of this error for a while after some time that error stop to be throwing. My resolution is from nexus 5 its means 1080 x 1920 pixels

Also I’ve more question, i would like some advises on there.

  1. First I want move a object during a collision i known that is impossible so i just create to object and just change the visible of them that disappear  of screen but physical body remains active, that is right? It’s possible to hide or disable physical interaction too?

  2. Second I’ve on object that i like to be on screen and have a physical behavior to detect collision but i’m not want this object have any reaction on collision like bounce and friction to do that i’ve use preCollision event to detect colission and I’ve set contact to false : event.contact.isEnabled = false that is the right think to do? 

Or i’ve other way to do this I notice that my device are spending much battery I fear that is because of preCollision event

Thanks in advance  

So, your config.lua settings are 1080x1920? Just double checking.

 

  • You can move an object just after a collision.  Simply wait one frame:

    timer.performWithDelay( 1, – 1 ms delay becomes one frame (delay > 0 and < ‘frame period’ == one frame wait) function() – move code here end )

  • You can effectively disable bodies and you can remove bodies, but not until after the collision is done processing (performWithDelay() again)

My config is this : 

content =
    {
        width = 0,
height = 0,
        scale = “letterBox”,
        fps = 60,

I’ve just run on a simulator with nexus 5 resolution, I want to use always the full screen of device.

Your performWithDelay is in pseudo code or i can use this piece of code, because i never find any documentation to able to do this. 

Can for all your quick response its will help me a lot.

Thanks in advance 

First, You’re welcome,
 
 
Second, no that wasn’t pseudo code (except that the comment was where you put your code):

Here is a more complete collision example with performWithDelay():

local function onCollision( self, event ) if( event.phase == "began" ) then -- Do something next frame to avoid physics violations timer.performWithDelay( 1, function() -- Do your 'something here' i.e. Write lua code to do work end ) end return true end

Third,
Again, I want to stress that I think that using auto- selected or calculated config.lua width/height is an extremely bad idea.  
 
You’re asking for an ambiguous work environment rife with questions, trouble, and surprises.  Basically what you’re encountering now.  
 
In my mind, the real purpose of config.lua is to create a known working environment.  Some seem to think, they can make a fixed design (their code) and somehow add code to config.lua to magically make their design fit.  This is upside-down thinking.
 
Sorry if I sound impassioned here. But I see this kind of misunderstanding and backwards thinking a lot and it’s hard to help folks after they’ve made a bad decision and decided it was the right one. :slight_smile:
 
My (not so humble opinion) is that you are best served by designing in this fashion:

** NOTE: My list below got corrupted and I’m not going to take time to correct it.  Sorry if this a a little confusing. **

  • Select a single base resolution that matches your primary market/device and encode that in config.lua.  A good choice is the iPhone 5.  It scales nicely up to iPhone 6 and the numbers are still small enough to do calculations on in your head when writing code.

  • Pre-calculate helpers as a module or globals (like I do) for such things as

    • w, h, fullw, fullh
    • left, right, top, bottom
    • unusedWidth/unusedHeight - Extra pixels on the current device. I use these less often now that I have left, right, … defined.
  • Adjust your app design to account for cases when you need to fill unused space and/or move elements to the edges of the screen.

  • Test, test, test.

  • Once you’ve mastered this approach, you’ll be better able to make alternate choices in config.lua.  However, starting from a completely undefined starting point will make life painful.  Again, my (not so) humble opinion.
     
    -Ed Out!

Hi again,
 
First I would like to thanks for your help I’m glad to learn with your ideas!
 
About my errors most of them already solved (thanks to you) I’ve remove my preCollision event and also I’ve solve my error when addBody() is called for this I’ve draw new pic and use again the physical editor to add again on my code. 
 
About auto selected or calculated config.lua width/height  you probably right I’ve been fighting  this since the beginning of my project, I try to follow your tips and have only on dev environment.

I think I’ve understand what you said create a global file where store variables that define the environment, however i’m not sure how I can get extra pixeis for a device that i’ve more that my definition for exemple for ipad mini have that screen on my game 

Even I’ve this 

https://drive.google.com/open?id=0BwJSv-5D6Hb2V1podjJERXBvTGM (see the pic)

local screenW, screenH = display.contentWidth, display.contentHeight

local background = display.newRect( 0, 0, screenW, screenH )

My backgroud dont use all of device screen but for example I use Admob to monetize and their banner are started at more left side of my screen, my doubt is how to get that extra pixels? To use them and make my code compensation like you suggest extra width and height 

Sorry to bore your with all of my questions

Hi.  Sorry, I’m having some trouble knowing what you’re asking, but I’ll give it a go:

1.You showed an image where the background was not covering all of the screen.  Make your images bigger so they cover the worst case screen size using your config.  Just make sure the most important part shows on your ‘target resolution’.  Then the extra width and height are for viewing on other sized devices.

Download this project, then run it with the various simulated devices ( iPad, iPhone5, Nook, etc. ) to see what I mean.  Then take a look at the image I used for the background.  See how it is extra wide and tall?  The pink part is extra for off-sized devices.

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/08/moreconfig.zip 

  1. Download this project and run it: 

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/08/config.zip

 

Notice how I calculate left, right, top, bottom etc?  I use these to handle cases where I want to align to the edges.  I also calculate unusedWidth and unusedHeight.  If these are non zero, I have extra pixels in that dimension.

 

 

  1. Finally look at this admob sample to see how to get your ads to align properly at the top of bottom and fill the whole width.

http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2015/06/admob.zip

Hi,

Thank for your reply again.

I’ve look to your sample and that awesome I just not know about display.actualContentWidth and display.actualContentHeight with that know i can scale my screen background to all width height of device.

What I’ve done is follow or tips and force a environment with some resolution for calculate all the movable objects that interact on game engine, my is only move object on Y axis. So I’ve compensate all background with that extra pixes to scale the image to full screen.

By the away I would like to ask one more question, for splash screen for example i’ve and image with 1080x1920 that is perfect for my forcing resolution, for device with low resolution them that is okay, however for much big screen with retina display what I’ve done for now is loading a high resolution picture by checking a device resolution with a if checking is more and 1080x1920 is there a way for doing that automaticly without if’s??

Thanks one more time you’re help me alot