Scale Method

So I was using the scale method to try to resize my app for an iPhone 5 or higher, but the touch function doesn’t get called, and every single item is still referenced to the full size touch function. Is there a way to automatically get items in the touch function to cooperate with the scale method? If not, I’m currently in the process of getting rid of hard coded values, and replacing them in respect to the width and height constants. I had no idea making the app compatible for iPhone would take so much work.

I usually copy each field of the touch into a new table (because touch is userdata so is readOnly) then change the x,y,lastX and lastY by the scale amount in their relative dimensions and then use this table like so

function touched(touch)
    local t=getTouch(touch)--deepcopy the touch into a table
    --change anything about the touch to ajust to scale and translations:
    t.x = t.x + 10
    --pass the new touch "t" to other functions:

function getTouch(touch)
    local t={};
    return t

I have a nice forgeTouch() function to generate a new metatable that is nearly identical to a normal touch instance, if you want to you can use it to scale all the variable by 0.5.

function forgeTouch(x, y, deltaX, deltaY, lastX, lastY, id, state, tapCount)
    local touch = {}
    touch.x = x
    touch.y = y
    touch.prevX = prevX
    touch.prevY = prevY
    touch.deltaX = deltaX
    touch.deltaY = deltaY = id
    touch.state = state
    touch.tapCount = tapCount
    touch.__tostring = function(t)
        return ""
        .. "\
    x:" .. string.format("%.6f", t.x) .. ", y:" .. string.format("%.6f", t.y)
        .. "\
    prevX:" .. string.format("%.6f", t.prevX) .. ", prevY:" .. string.format("%.6f", t.prevY)
        .. "\
    id:" .. string.format("%9.0f",
        .. "\
    state:" .. t.state
        .. "\
    tapCount:" .. t.tapCount
    setmetatable(touch, touch)
    return touch

@Coder You know there’s getmetatable and setmetatable, right? “userdata” is just a metatable.

Yep i need to read up on metatables

@Coder, metatables are pretty useful, if you ever need to mess with (change the functionality of) things like color, tween, music, you’ll be glad you learned them :slight_smile:

@YoloSwag - professional programmers will tell you the simple answer is never to hard code anything. Put all your constants into variables. I often have a Settings function where I do this all in one place.