Dynamic image size for all ios devices

Hello,

I am working on one project that is only for IOS.
I am using below config.lua :
 

local targetDevice = ( system.getInfo( “model” ) ) 

local isTall = ( “iPhone” == system.getInfo( “model” ) ) and ( display.pixelHeight > 960 )

if isTall == false and targetDevice == “iPhone” then

application = 

{

    content = 

    {

        width = 320,

        height = 480,

        scale = “letterbox”,

        fps = 60,

                --antialias = true,

                xalign = “center”,

                yalign = “center”,

        imageSuffix = 

        {

            ["@2x"] = 2,

        },

    },

}

elseif isTall == true then

application = 

{

    content = 

    {

        width = 320,

        height = 568,

        scale = “letterbox”,

        fps = 60,

                antialias = true,

                xalign = “center”,

                yalign = “center”,

    },

}

elseif targetDevice == “iPad” then

application = 

{

    content = 

    {

        width = 768,

        height = 1024,

        scale = “letterbox”,

        fps = 60,

                --antialias = true,

                xalign = “center”,

                yalign = “center”,

        imageSuffix = 

        {

            ["@2x"] = 2,

        },

    },

}

end

I want to know that what is the best way to set image size for both orientation.
My app is in both orientation and i am recreating all the objects on device orientation change(Runtime listener for orientation)

for eg.

if i use fix pixel like:

local myImg = newImageRect(“myImg.png”,100,100)

Then this is not proper for ipad ratina and high resolution devices.

My code is like below:

_W = display.contentWidth

_H = display.contentHeight
local function createMyImage()

     

     local imgSize = _W/2

     local myImg = newImageRect(“myImg.png”,imgSize,imgSize)
     myImg.x = _W/2 
     myImg.y = _H/2

end
createMyImage()
 

local function onOrientationChange(event)

     DeviceOrientation = event.type

    _W = display.contentWidth 

    _H = display.contentHeight

     createMyImage()

end

Runtime:addEventListener( “orientation”, onOrientationChange )


I know that this is not a proper way to set image.
Please help me for this problem.

Thanks in advance.

I would recommend you to use this config .lua

application = 

{

    content = 

    { 

        width = 640 * (display.pixelHeight/display.pixelWidth>1.5 and 1 or 1.5/(display.pixelHeight/display.pixelWidth)),

        height = 960 * (display.pixelHeight/display.pixelWidth<1.5 and 1 or (display.pixelHeight/display.pixelWidth)/1.5),

        scale = “letterbox”,

– xAlign = “center”,

– yAlign = “center”,

        imageSuffix =

        {

            ["@2x"] = 2,

            ["@4x"] = 3.0,

        },

    },

}

So that it will properly fits all ur objects .

Hi.  I still advocate the (very) old ‘Magic Recipe’ Solution: http://coronalabs.com/blog/2010/11/20/content-scaling-made-easy/

Benefits:

  • Displays well on all devices.
  • Easy to calculate in your head (i.e. working with a design space of 320x480 makes math simple).
  • It is consistent.  I don’t care for config files that change the ‘design resolution’ because I like to choose absolute positions for some content (especially interfaces).
  • It is short.  Only one small recipe is way easier to test and validate than a dynamically adjusting one, or one with a bunch of if-then-else cases. 

Drawbacks:

  • Without proper handling, you can waste space on an iPhone 5 or iPad screen.  I handle this by calculating unused width/height and including it in my game/apps designs.  i.e. If a screen is extra tall (like iPhone 5) and if it is appropriate, I dynamically adjust the vertical position of some or all elements.  The config file is the same, but my app adjusts.
  • It’s old.  Not really a drawback, but some seem to think so.

-Cheers

Thank you roaminggamer and kumarks102.

 

Now I am using this Config :

Is this okay for all ios devices ?

Thank you.
 

@Panarabk,

It will work on all current iOS devices, however you’ll want to adjust parts of your game or interface on wider and taller devices, as per my discussion in drawbacks above.  Look at the display.* variables to calculate extra width and/or height.

Also, I’ve yet to see this on the upcoming wide iPhones (as rumored) 4.7" and 5.5".  Howe well this works depends on the aspect ratio of those devices.

Thank you so much RoamingGamer. 

I want one more help from you if you can.

I really need help about below topic;
http://forums.coronalabs.com/topic/49805-how-to-use-multiple-plugins-in-a-single-app/

Please help me and Please let me know if you can’t understand anything in my posted question.

Thank you so much. :slight_smile:

I would recommend you to use this config .lua

application = 

{

    content = 

    { 

        width = 640 * (display.pixelHeight/display.pixelWidth>1.5 and 1 or 1.5/(display.pixelHeight/display.pixelWidth)),

        height = 960 * (display.pixelHeight/display.pixelWidth<1.5 and 1 or (display.pixelHeight/display.pixelWidth)/1.5),

        scale = “letterbox”,

– xAlign = “center”,

– yAlign = “center”,

        imageSuffix =

        {

            ["@2x"] = 2,

            ["@4x"] = 3.0,

        },

    },

}

So that it will properly fits all ur objects .

Hi.  I still advocate the (very) old ‘Magic Recipe’ Solution: http://coronalabs.com/blog/2010/11/20/content-scaling-made-easy/

Benefits:

  • Displays well on all devices.
  • Easy to calculate in your head (i.e. working with a design space of 320x480 makes math simple).
  • It is consistent.  I don’t care for config files that change the ‘design resolution’ because I like to choose absolute positions for some content (especially interfaces).
  • It is short.  Only one small recipe is way easier to test and validate than a dynamically adjusting one, or one with a bunch of if-then-else cases. 

Drawbacks:

  • Without proper handling, you can waste space on an iPhone 5 or iPad screen.  I handle this by calculating unused width/height and including it in my game/apps designs.  i.e. If a screen is extra tall (like iPhone 5) and if it is appropriate, I dynamically adjust the vertical position of some or all elements.  The config file is the same, but my app adjusts.
  • It’s old.  Not really a drawback, but some seem to think so.

-Cheers

Thank you roaminggamer and kumarks102.

 

Now I am using this Config :

Is this okay for all ios devices ?

Thank you.
 

@Panarabk,

It will work on all current iOS devices, however you’ll want to adjust parts of your game or interface on wider and taller devices, as per my discussion in drawbacks above.  Look at the display.* variables to calculate extra width and/or height.

Also, I’ve yet to see this on the upcoming wide iPhones (as rumored) 4.7" and 5.5".  Howe well this works depends on the aspect ratio of those devices.

Thank you so much RoamingGamer. 

I want one more help from you if you can.

I really need help about below topic;
http://forums.coronalabs.com/topic/49805-how-to-use-multiple-plugins-in-a-single-app/

Please help me and Please let me know if you can’t understand anything in my posted question.

Thank you so much. :slight_smile: