Is it possible to access an images x and y axis outside of sprite()?

Is it possible to access an images x and y axis outside of sprite()?

My Code:

--# Main

function setup()
    
    Player1NumberElexir=0
    elexir=0
    objects = {} 
    parameter.watch("CurrentTouch.y")
    parameter.watch("CurrentTouch.x")
    parameter.watch("elexir")
    parameter.watch("Player1NumberElexir")
end

function draw()
    
    background(40, 40, 50)
    
    
    elexir=elexir+1
    
    if elexir==80 
    then
    Player1NumberElexir=Player1NumberElexir+1
    elexir=0
    end
    
    for i, o in pairs(objects) do
        o:draw() 
    end

end

function touched(touch)    if CurrentTouch.y < HEIGHT/2 and Player1NumberElexir>=2 and touch.state==BEGAN then
        table.insert(objects,Object(touch.x,touch.y))
        Player1NumberElexir=Player1NumberElexir-2
        
end


--# Object


end
Object = class()

function Object:init(x,y)
    self.x = x
    self.y = y
end

function Object:draw()
    stroke(255, 255, 255, 255)
    strokeWidth(5)
    fill(29, 114, 133, 255)
 sprite("Project:army 1",self.x,self.y,50)
end

Can you explain your question in more detail. I’m not sure what you’re asking. Another thing, if you’re going to use the function touched, then don’t use CurrentTouch. Once you learn how the touched function works, you’ll probably never use CurrentTouch anymore.

EDIT: I tried your program and it looks like you’re just placing a Sprite at some screen position you touch. So I’m not sure how that relates to your question.

What I’m asking is if you can acess the x and y value of a image outside of the when you first instate the sprite. For example outside of the sprite(MyImage,100,100)

If you say sprite(image,100,100), then that’s the only time you know where that image is at, 100,100. If you create a table that holds the x,y position of an image, or hundreds of images, then you can access any entry in the table to find out where an image is at or to change its values. Is that what you’re asking.

Remember when you were a kid and used stamps to draw shapes on paper. You’d dip a stamp in ink and press it on the paper. Your drawing tools are the stamps, and once you stamp something, you can’t move it left or right, or delete it without drawing over it.

In Codea, the stamps are the images themselves, and the paper is the screen. When you sprite, you are “stamping” an image to the screen, and once you do that, it becomes part of the screen. You can’t say “move that image I just sprited, or where is pixel (3,2) of the image I sprited?”. Once you draw something, it becomes part of the screen, and is not an object you can use. It’s up to you to remember where you drew stuff, if you want to add to your picture.

Ok, thanks!

@magicskillz Here’s an example of putting a sprites x,y values in a table, displaying a sprite at the x,y position, and then changing the x,y values.

displayMode(FULLSCREEN)

function setup()
    tab={}
    for z=1,20 do   -- create original x,y positions for 20 sprites
        table.insert(tab,vec2(math.random(WIDTH),math.random(HEIGHT)))
    end
end

function draw()
    background(0)
    for a,b in pairs(tab) do
        sprite("Platformer Art:Battor Flap 1",b.x,b.y)
        b.x=b.x+math.random(-2,2)    -- change the x,y values
        b.y=b.y+math.random(-2,2)
    end
end