Another one for Dynamic Content Scale

Hello everyone, I am struggling with the config.lua file for my project. My main issue is the fact that, instead creating a 320x480 (iPhone) and resize the images, I created an iPad project and downsize the images.

I figured out a way to handle the “downsize” for the iPhone but, for iPhone4, I do not have success (it shows the images for the iPhone, instead the ones for the iPad). Any ideas on what am I doing wrong here?

My config.lua file below:

[code]
if system.getInfo(“model”) ~= “iPad” and system.getInfo(“model”) ~= “iPhone4” then
application =
{
content =
{
–zoom
width = 768,
height = 1024,
fps = 60,
scale = “zoomStretch”,

imageSuffix =
{
["@2"] = 1,
}
}
}
elseif system.getInfo(“model”) == “iPhone4” then
application =
{
content =
{
width = 768,
height = 1024,
fps = 60,
scale = “zoomStretch”,

imageSuffix =
{
["@2"] = 1,
}
}
}
else
application =
{
content =
{
width = 768,
height = 1024,
fps = 60,
scale = “zoomStretch”,

imageSuffix =
{
["@2"] = 1,
}
}
}
end
[/code] [import]uid: 4883 topic_id: 8918 reply_id: 308918[/import]

I’m using this in my main.lua file (using director):

suffix = "" -- won't work local  
   
if display.contentScaleX \> 1.3 then -- iPhone 3 is "2.13", iPad and iPhone 4 "1.06" and "1".   
suffix = "@50" -- your suffix @50= 50% for me  
end  

in your config.lua set width = 768, height = 1024 (for landscape) to get display.contentScaleX = 1 for iPad and so on)

don’t set any suffix table

Now you call :

local yourimage = display.newImageRect("ipadSizeimage"..suffix..".png", 400, 400)  
--iPad image size 400 x 400  
print("ipadSizeimage"..suffix..".png") -- check which image you're getting  

That’s it!

It’s a shame having to place the suffix code everytime but it’s the only workaround I know

The credit goes to comes AdamBucketz and his code on getting dynamic retina sprites. http://developer.anscamobile.com/forum/2010/12/08/dynamic-retina-spritesheets-heres-how#comment-15849 [import]uid: 10426 topic_id: 8918 reply_id: 35094[/import]

a slightly more modular way is to just insert an “imageName(‘ipadSizeimage’)” function into all of your display.newImageRect( funcGoesHere() ) calls so you don’t have to mess with changing specific calls if you learn a new trick later [import]uid: 6175 topic_id: 8918 reply_id: 35231[/import]