A way to check devices in Codea?

Hi everybody! With all the helpful tutorials here on Codea on making an universal app, I was wondering if Codea has some way to check what device you are using as I do not know how to do this on Xcode. Also, I have already finished most of my game, but unfortunately when I compiled it on Xcode, it only runs correctly on the iPad and not any of the iPhones as the buttons are too large along with a lot of other stuff. So I am thinking of making two versions in Codea. One for the iPad and one for the iPhone. The only problem is that I do not know how to tell Xcode which one to display.

I greatly appriecate any advice on this subject as I am completely new to Xcode this year!

@YoloSwag Is this what you’re after.


function setup()
    for a,b in pairs(deviceMetrics()) do
        print(b)
    end
end

@dave1707. Yes! So, say if I were to implement this across my app for the iPhone 5 and 5s. Would I have to say…

if b== iPhone5,1 or if b==iPhone 5,2 then
--some variable that becomes true when the user in on an iPhone 
iphonecheck==true 
end

And then for the rest of my app I can just make the precondition that iphonecheck must be true for it to display the different format. Would this work seamlessly in Xcode?

Thank you!

@YoloSwag I’m not sure what the iPhone 5 would show, but you need " " around it. See below for “iPad4,1” .


function setup()
    for a,b in pairs(deviceMetrics()) do
        print(a,b)
        if b=="iPad4,1" then
            print("true")
        end
    end
end

@YoloSwap This might work even better.


function setup()
    if deviceMetrics().platform == "iPad4,1" then
        print("true")
    end
end

@YoloSwag, there is no need to check the device type. I just finished re-coding one of my games to make it universal for all devices. For iPads, the width = 768 and height = 1024 so just use

w = WIDTH/768
h = HEIGHT/1024

and then multiply all x values by “w” and all y values by “h”. This will make a percentage where each percent is equal to one pixel on your iPad, but it looks the same on all devices.

@YoloSwag You don’t need to add extra code to multiply all of the x or y values by something. Just code everything like you normally would and then use one “scale” command to resize everything based on the device you want to use it on. See the example I have in the discussion called “scale command”. I don’t have an iPhone 4 or 5, so I don’t know for sure how it really looks. Like @Staples says, the WIDTH and HEIGHT can be used.

Thank you @dave1707 and @Staples. At least I know that I have many options for making this work.

@YoloSwag @dave1707 What about the difference in width-to-height ratios between iPads and iPhones?

@SkyTheCoder I don’t have an iPhone 4 or 5 so I can’t say for sure, but if you draw a circle on each of the different devices, it should be a circle and not an ellipse. The width to height ratio should only affect the distance between different objects. If you draw 4 circles at points that would form a perfect square on one device, those four circles probably won’t be at the points to form a perfect square on the other devices. The iPad has a 1x1.33 ratio. The iPhone 4 has a 1x1.5 ratio and the iPhone 5 has a 1x1.775 ratio. So if you want everything to be perfect, then you code for each device differently, but I’m not sure if it matters that much.

@dave1707 You suggested scaling drawing by WIDTH / 1024, HEIGH / 768. If it was a different ratio, objects would be stretched/squeezed to fit.

@SkyTheCoder I think as long as objects are drawn with specific values, ellipse(x,y,20), the screens would look very similar. But if some objects were also drawn using some value from WIDTH or HEIGHT, ellipse(WIDTH-x,HEIGHT-y,20), because of the different aspect ratios, the screens might look a little different. Without seeing the results on an iPhone 4/5, I can’t say how noticeable it will be.

@dave1707, @SkyTheCoder, yes if you use scale(WIDTH / 1024, HEIGHT / 768) a circle would look like an ellipse.

Here is an example:

function draw()
    scale(WIDTH / 1024, HEIGHT / 768)
    
    background(0)
    
    fill(255)
    ellipse(350, 350, 200)
end

This will display a proper circle using displayMode(FULLSCREEN) in landscape, but in portrait or in displayMode(STANDARD) it will be squished.