[Question] Sprite buttons

Does somebody knows how to make a sprite a button? I want to make every building to be a button…

Here’s the code:

displayMode(FULLSCREEN)

function setup()
    score = 0
    lives = 10
    objects = {}
    table.insert(objects, {WIDTH/2, HEIGHT/2, 10})
    target = vec2(WIDTH/2, HEIGHT/2)
end

function draw()
    background(34, 109, 31, 255)

    sprite("Small World:Base Large", WIDTH/2, HEIGHT/2.15, 100)
    sprite("Small World:House White", WIDTH/1.5, HEIGHT/1.5, 150)
    sprite("Small World:House White", WIDTH/4, HEIGHT/7, 150)
    sprite("Small World:Church", WIDTH/3, HEIGHT/1.19, 150)
    sprite("Small World:Store Extra Large", WIDTH/1.300, HEIGHT/6, 150)
    sprite("Small World:Fountain", WIDTH/8, HEIGHT/2, 150)

font("AmericanTypewriter")
fill(0, 0, 0, 255)
strokeWidth(10)
    rectMode(CENTER)
    rect(WIDTH/10,HEIGHT/1.1,150,150)
    rect(WIDTH/1.1, HEIGHT/1.1, 150, 150)
    rect(WIDTH/1.1, HEIGHT/9, 150, 150)
    textWrapWidth(110)
    fontSize(20)
    fill(255, 255, 255, 255)
    text(os.date(), WIDTH/10, HEIGHT/1.1)
    text(lives, WIDTH/1.1, HEIGHT/1.12)
    text("Lives:", WIDTH/1.1, HEIGHT/1.08)
    text("score", WIDTH/1.1, HEIGHT/7)
    text(score, WIDTH/1.1, HEIGHT/10)

for i,v in ipairs(objects) do
    move = target - vec2(v[1], v[2])
    if move:len() > v[3] then
        move = move:normalize() * v[3]
    end
    v[1] = v[1] + move.x
    v[2] = v[2] + move.y

    sprite("Space Art:UFO", v[1], v[2], 75)
    end
end

function touched(touch)
    target = vec2(touch.x, touch.y)
end

The sprites themselves aren’t touchable per se. What you need to do is create some kind of logical representation of how the sprites appear on screen, then you can evaluate the touch target against that.

So, if your objects table had the x,y coordinates and size of each sprite, then you could draw the sprites based on this table, and also evaluate the touch on this table as well. Basically exactly as you are doing for the “UFO”, but for all sprites.

Thanks, I’ll try that.