Corona SDK Ragdoll Sample bug?

In the file “ragdoll.lua” provided in the ragdoll sample app, the following code is provided to create the head: 

    – Head

    local head = display.newCircle( startX, startY, 12.5 )

    setFill(head, colorTable)

    ragdoll:insert (head)

However, when I tweak it to, for instance, 

   local w,h = 2*15,2*10

  local head = display.newRect( -w*0.5, -h*0.5, w, h )

so that the head should theoretically now be a rectangle, the head doesn’t change! No matter what I do or how I change it, the circular head is always the same. Is this a bug? How can I change the head? I’m new to corona and am just playing around with the sdk. Thanks!

Hi @summer,

When you say that the head doesn’t change, do you mean, it remains a circular-shaped physics object? Despite the fact that the visual object is now a rectangle? If so, this is because you need to let Box2D create a rectangular body shape, not a radial shape, by removing the “radius” parameter from the “physics.addBody()” API call. If you post a little code, I can probably pinpoint the exact code bit to change.

Hope this helps,

Brent

Thanks so much Brent! You were absolutely right! I just have one follow up question- I’m now trying to make the head an image rather than just a rectangle. While the head is the same size as the image should be, it’s the same translucent brown color as the rest of the body rather than the opaque image I would expect. Here’s my code (feel free to ignore all the comments!):

    – Head

    local head = display.newImage(“image.jpg”, system.TemporaryDirectory, startX, startY, true)–display.newCircle( startX, startY, 12.5 )

    --head.fill = { type=“image”, filename=“self.jpg”, baseDir = system.TemporaryDirectory }

    --head.x = startX

    --head.y = startY

    --setFill(head, colorTable)

    

    ragdoll:insert (head)

Do you know how I can get the image to show up? Thanks again!

Hi @summer,

Your display of the image seems correct, basically. Do you want to “trace” the actual head with a physics body that matches its approximate shape? If so, you need to create a polygon physics body shape.

The translucent brown shape you’re seeing in the “hybrid” physics mode is probably because you’re using a rectangle that surrounds the entire image (including transparent space). To make a more accurate shape, please see “Polygonal Bodies” in the following guide:

http://docs.coronalabs.com/guide/physics/physicsBodies/index.html

Take care,

Brent

The shape of the actual image is actually a rectangle, so I’d assume that making a polygonal body wouldn’t make too much of a difference. The problem is that the image doesn’t show up; in other scenes when I use the same code, it does, but not in the ragdoll case…

Hi @summer,

Is there a specific reason why you’re trying to access images in the device’s temporary directory? Are you certain the file(s) exist there when you make the image call?

Brent

Hi Brent, there’s no specific reason why I’m trying to access images in the device’s temporary directory, although when I changed it to the DocumentsDirectory, the same problem occurred. Yes, I’m certain that the file exists when I make the image call- I made sure to check in the folder first! I would just like a way to display an image that was just taken.

@Brent if it helps, here’s my code: https://github.com/sw5813/ragdollifyyourself

Hi @summer,

In which environment does the image not show up? I just downloaded your project, tested it in the Simulator, and it works fine… the image shows up (camera shot), attaches it as the “head” of the rag doll, and the physics behaves as expected.

I haven’t deployed this to a device yet… is that where the issue is?

Brent

Hi Brent, yes actually, the problem seems to arise on my Android phone- it works fine in my simulator too! I suppose then, that it’d be a problem with my Android-specific configuration?

Instead of placing the captured photo on the screen then “display.save()”-ing it, how about just saving the file directly to the Documents directory on the capture?

See the second example at the bottom of this page:

http://docs.coronalabs.com/api/library/media/capturePhoto.html

The reason I captured the photo on the screen is because I found that to be an easy way to resize the image- is there a way to save a thumbnail with the capturePhoto API? Also, I don’t think that would affect whether the image shows up or not on Android…

Hi @summer,

Before we proceed, does the “Camera” sample app work on the same Android device? It’s in your local Corona application directory:

CoronaSDK > SampleCode > Media > Camera

This sample uses “media.show” which is deprecated but not vastly different than “capturePhoto()”, so it should reveal if there’s some issue with your settings or not.

Thanks,

Brent

Hi Brent, the camera app works fine! Although the image taken on the phone seems to be far larger than the screen size, causing only a portion of the image to show up after it has been captured…

Hi summer,

Do you mean, when you run the sample project with absolutely no modifications, the image shown on the screen after you take the camera shot is much bigger than the screen, and flows off the screen in all directions?

Brent

exactly!

Hi @summer,

I’ve confirmed this behavior on my side, and it appears to be a bug. I’ve asked the engineers to investigate.

In the meantime, won’t you be scaling the object (photo) regardless, to fit on the rag doll?

Thanks,

Brent

Great, I really appreciate it! How can I be notified if/when the bug is fixed? And indeed, it appears that I will. Thanks for all your help, Brent! 

Hi summer,

I learned from the engineers that this isn’t a bug. Windows and Android do not automatically downscale and reduce the memory footprint of an image to fit the screen like Mac and iOS does. That is, you’ll run into the same issue if you call display.newImage() with that exact same photo that is too big to fit the screen. Mac and iOS will automatically downscale it, but Windows and Android won’t. So, the solution is what you’re probably doing already: downscale it to the size you need and go from there.

Best regards,

Brent

Hi Brent, the problem isn’t that the image is too big- I already have downsized it. The problem is that it does not show up at all.