Posted on by

Frequently Asked Questions

It’s Wednesday and time for another FAQ session. Here are some frequently asked questions (FAQ) about display objects.

1. Why is my iOS App file larger with Daily Builds compared to building with the release build (894)?

Starting with build 900, PNGCRUSH is no longer called for iOS “developer” builds. This was added to speed up build times but it does mean that the PNG images will not be compressed, which will increase the size of your app. Building for AdHoc or Distribution has not changed and calls PNGCRUSH as before.

2. How can I load images that are larger than the device’s screen size, without it scaling down the image?

display.newImage will scale images to fit the screen dimensions of the device. You can set the “isFullResolution” flag to true to disable the automatic scaling.

The display.newImageRect does not automatically scale down images when loaded. For this API you must specify the width and height of the image, so that is another way to load an image larger than the device’s screen size.

Be aware that devices have a maximum resolution that can be loaded which is typically 2048 x 2048.

3. If I put code like display.newRect(0, 0, 80, 40), at coordinates 0,0, my rectangle will appear cropped at top-left of the mobile screen.

The object should not be chopped because when a newRect is created, it’s created with a TopLeft reference. So 0,0 will position the top left corner of the rect at the top left of the screen. It may look chopped if you have the status bar visible. You can turn off the status bar as follows:

Most display objects are created using a TopLeft reference point. After the object has been created, the reference point changes to Center reference. Here is one way to center the rect on the screen.

The following will NOT correctly center the rect, but position the TopLeft corner of the rect in the center of the screen.

The TopLeft reference for creating display objects apply to all objects except for display.newCircle and The display.newGroup. display.newCircle is created with Center reference and display.newGroup is empty and has no reference point until objects are inserted. Once objects are inserted into a group, it has a TopLeft reference.

4. setReferencePoint is not working when I use display.topCenterReferencePoint. What’s wrong?

The parameter for setReferencePoint must be spelled correctly and with the proper capitalization or it won’t work. The correct value to set the Top Center reference point is, display.TopCenterReferencePoint (with a capital “T”). Unfortunately the API doesn’t give you a warning or error message when the parameter is incorrect. This is on our list to fix in the future.

That’s it for today’s questions. I hope you enjoyed it and even learned a few things.


Posted by . Thanks for reading...

6 Responses to “FAQ Wednesday: Display Objects”

  1. George

    Thanks Tom. Even for someone who has been working with Corona SDK for a long time, the reference point thing still confuses me like crazy. This blog has definitely helped me understand some of the weird stuff I’ve seen.

    It seems really counter intuitive that this –
    local rect = display.newRect( 0, 0, 80, 40 )
    rect.x = display.contentCenterX
    rect.y = display.contentCenterY

    Is not the same as
    local rect = display.newRect( display.contentCenterX, display.contentCenterY, 80, 40 )

    And then display.newGroup is TopLeft when almost everything else is Center…?

    I’ve gotten into the habit of re-setting the reference point and re-positioning every object I work with after it’s created.

    Reply
  2. J. A. Whye

    Great info in this blog post, thanks!

    Like George, I’ve gotten into the habit of explicitly setting the X and Y properties of objects after I create them. Otherwise it just gets insane. :)

    Jay

    PS – Typo in the description for #4 – look for the missing “n” in this: display.TopLeftCenterReferecePoint

    Reply
  3. Tom Newman

    Thanks everyone for your comments. I fixed the typos and changed TopLeftCenterReferencePoint to TopCenterReferencePoint.

    @Georoge, It is confusing because the reference point effectively changes on display objects after the object is created. So the newRect is created with TopLeftReferencePoint and then becomes CenterReferencePoint.

    display.newGroup is different because it’s an empty object (has no x, y, width, height) when created.

    We have talked about trying to makes things consistent and less confusing. I find myself setting the x/y values after the object is created so I don’t have to think about it :)

    Reply
  4. Antheor

    I have indeed troubles with
    local image = display.newImage( “myImage.png”, 0, 0 )

    Using newImageRect is ok, but newImage is not center Referenced even when I do :

    -- that doesn't work (image is top lefted) :
    loca image= display.newImage( layer,mainsheet, 2,display.contentCenterX,display.contentCenterY)

    -- that doesn't work (image is top lefted) :
    loca image= display.newImage( layer,mainsheet, 2,0,0)
    image:setReferencePoint( display.CenterReferencePoint )
    image:translate(display.contentCenterX,display.contentCenterY)

    -- that works (but don't get profit of imagesheets)
    local image=display.newImageRect(layer,"myimage.png",100,100)
    image:translate(display.contentCenterX,display.contentCenterY)

    This is quite annoying since I don’t want to set my image dimensions here, but rather in my sheet.lua ( as everybody recommends).

    Could you help or advice ?

    Reply

Leave a Reply

  • (Will Not Be Published)