What sizes of images do I need for background and sprites in corona to support android/iphone

一曲冷凌霜 提交于 2019-12-25 06:28:03

问题


I like that corona compiles to multiple environments, but I want to know what size sprites, and images do I need. I mean I don't have time to create separate images for every conceivable device size. I know corona supports some auto scaling of images. So for example if I have a 64x64 sprite is that all I need? or do I need new image sizes for every scenario? I am looking for 80% coverage not perfect for every device.


回答1:


I'm doing it in a different way. I think this may help you. As my opinion, just create multiplier values for width and height(according to which simulator you are coding in), and multiply your each width or height parameter with this(as below):

--------------------------------------------------------------------------
   -- choosing xMultiplier and yMultiplier values --
--------------------------------------------------------------------------
   local xMultiplier = display.contentWidth/320  
   local yMultiplier = display.contentHeight/480
   --[[ I used 320 here because i'm using iPhone Simulator 
        (320 is the width of the simulator you are coding in)
        I used 480 here because i'm using iPhone Simulator 
        (480 is the height of the simulator you are coding in)--]]

--------------------------------------------------------------------------
   -- creating background and positioning it --
--------------------------------------------------------------------------
   local bg = display.newImageRect("bg.png",320*xMultiplier,480*yMultiplier)
   bg.x = 160*xMultiplier ; bg.y = 240*yMultiplier

--------------------------------------------------------------------------
   -- creating object and positioning it --
--------------------------------------------------------------------------
   local rect = display.newImageRect(0,0,50*xMultiplier,50*yMultiplier)
   rect.x = 160*xMultiplier ; rect.y = 100*yMultiplier

--------------------------------------------------------------------------

Note: If you are using config.lua file in your project, this may not work.

Pros: This needs only one image.

Cons: It may affect the clarity of images in devices with high resolution. So choose an image with suitable resolution.

keep coding... :)




回答2:


I suggest you watch:

Big Corona Meetup - Part 1 - Corona SDK on youtube.

The second speaker goes into image scales, and how to do this with all devices. Also covers how to position objects in the right part of the screen when using different devices.




回答3:


You really have two choices to go with, depending on your game and content you have.

You can either use the magic formula for letterbox scaling, which is presented in here: http://blog.anscamobile.com/2010/11/content-scaling-made-easy/

or, if you need, you can combine the above with loading different resolution images, which is described in here: http://blog.anscamobile.com/2010/11/content-scaling-made-easy/

This means, that you will end up with over 90% of devices covered and depending on your needs with crisp looking graphics on different devices.




回答4:


Create multiple images with different sizes.
This is the choice i am going with now,
let's assume base image has size 100x70 and base screen res is 320x480.

baseImage.png       100x70  | 320x480  for IPhone and Android mdpi normal screen
baseImage@2.png     200x140 | 640x960  for IPhone 4
baseImage@ipad.png  213x149 | 768x1024 for IPads and Android mdpi xlarge screen
baseImage@hdpi.png  150x105 | 480x800  for Android hdpi normal screen

based from here:

top 3 Android screen density and size
hdpi normal 66.3% 
mdpi normal 18.5%   
mdpi xlarge  4.9%   

First, change all image initialization code to use newImageRect().
It will load the corresponding image file with the nearest resolution and ratio.
If no better fit was found it will load the base image.

local img = display.newImageRect("baseImage.png",100,70) 
--100 is base width
-- 70 is base height

then set a base resolution for the app and naming convention for multiple res images in config.lua.

application =
{
    content =
    {
        width = 320,
        height = 480,
        scale = "letterBox",
        xAlign = "center",
        yAlign = "center",

        imageSuffix =
        {
            ["@2"] = 2,
            ["@ipad"] = 2.133, --1024/480
            ["@hdpi"] = 1.5,   --480/320
        },
    },
}

Summary: The screen will zoom to show all stuff on screen. It will automatically load the smallest possible image. The cons is on devices with ratio 1.5 or above there will be excess black area on left and right side of the screen.

That's all I hope.
We don't have IPad 3 (with a ridiculous 2048x1536 res) for testing yet, so I can't comment.



来源:https://stackoverflow.com/questions/8651591/what-sizes-of-images-do-i-need-for-background-and-sprites-in-corona-to-support-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!