Why are my images not appearing properly

It’s kinda annoying. I do all this collision detection stuff and write code to position my rectangles and cookie sprites, but eventually everything shifts both in size and position when I test it, occasionally. Why? D;

Thanks for reading.

Need more information than that. How about some code.

Ok…it’s a little messy, I’m not a codea expert. Check the drawer function at the bottom:

function setup()
    cpsInfo = {
        {
            {
                name = "Autoclicker";
                price = 50;
                action = "cps";
                cpsGiven = 1;
                pos = vec2(19,HEIGHT - 70);
                size = vec2(210,50);
            }
        };
    }

    cpsPositioning = {}
    clicking = false
    clickTimer = 0 
    cookieTimer = 60
    cookieStats = {
        cookies = 0;
        cps = 0;
        cpc = 1;
    }
    cookieSpecs = {
        pos = vec2(WIDTH / 1.5,HEIGHT / 2);
        size = vec2(100,100);
        posX = 550;
        posY = 500;
        sizeX = WIDTH / 1.5;
        sizeY = HEIGHT / 2.5;
        shrunk = false;
    }
    page = 1
    purchasing = false
    currentTap = nil
end

function WithinBounds(element,x,y)
    if  x > (element.pos.x - 100) and x < (element.pos.x + 140) and y > (element.pos.y - 120) and y < (element.pos.y + 150) then
        return true
    end
end

function IsOnButton(x,y)
    for i,v in pairs(cpsInfo[page]) do
        if x > (v.pos.x) and x < (v.pos.x + v.size.x) and y > (v.pos.y) and y < (v.pos.y + v.size.y) then    
            return v
        end
    end
end

function touched(tap)
    if not purchasing and not clicking and tap.state == BEGAN and                   WithinBounds(cookieSpecs,tap.x,tap.y) then
        clicking = true
        cookieStats.cookies = cookieStats.cookies + cookieStats.cpc
        sound(SOUND_PICKUP, 12422)
    elseif not purchasing and not clicking then
        clicking = true
        local b = IsOnButton(tap.x,tap.y)
        if b then
            if cookieStats.cookies >= b.price then
                purchasing = true
                cookieStats.cookies = cookieStats.cookies - b.price
                cookieStats.cps = cookieStats.cps + b.cpsGiven
                b.price = (math.floor(b.price * 1.13))
                purchasing = false
            end
        end
        clicking = false
    end
end

function draw()
    background(178, 138, 32, 255)
    if clicking and WithinBounds(cookieSpecs,CurrentTouch.x,CurrentTouch.y) then
        if not cookieSpecs.shrunk then
            shrunk = true
            cookieSpecs.sizeX = 97
            cookieSpecs.sizeY = 97
        end
        clickTimer = clickTimer + 1
        if clickTimer > 5 then
            cookieSpecs.sizeX = 100
            cookieSpecs.sizeY = 100
            shrunk = false
            clicking = false
            clickTimer = 0
        end
    end
    sprite("Project:cookie",cookieSpecs.posX,cookieSpecs.posY,cookieSpecs.sizeX,cookieSpecs.sizeY)
    fill(255, 213, 0, 255)
    fontSize(25)
    font("ArialRoundedMTBold")
    text(cookieStats.cookies.." Cookies",430, 950)
    text(cookieStats.cps.." Cookies Per Second",430, 900)
    text(cookieStats.cpc.." Cookies Per Tap",430, 850)
    fill(128, 104, 30, 255)
    strokeWidth(5)
    stroke(204, 169, 35, 255)
    rect(0,0,250,HEIGHT)
    for i,v in pairs(cpsInfo[page]) do
        rect(v.pos.x,v.pos.y,v.size.x,v.size.y)
        fill(187, 204, 43, 255)
        fontSize(16)
        text(v.name..": "..v.price.." Cookies",125,HEIGHT - 70 + 25)
    end
end

@Coder1500 Maybe a little more detail about what your problem is would be helpful. Such as, what do I have to do to make something happen and what isn’t it doing that you think it should. When I run your code, the Sprite shows with a size set by WIDTH/1.5 and HEIGHT/2.5 in setup. If I touch the Sprite, the Sprite size changes to 97,97. After a short time, the Sprite size changes to 100,100. That’s what you have coded. Other than that, what’s changing position and size that you think is wrong.

@Coder1500 One other thing I noticed was if you’re in portrait orientation, your 3 text statements show, but if you’re in landscape mode, the text doesn’t show. The reason for that is you have the x,y values hard coded. In landscape mode, the values are more than the height of the screen. You need to determine which orientation you want your program to run in and set that with supportedOrientation. If you want your program to run in either mode, then you need to show things based on the WIDTH and HEIGHT values which change if you rotate the device.

Oh that makes sense Dave. Thank you for this information!