Trying to create simple touch image move and need some help

I want it to only move when I touch the image and drag it around.

I followed this tutorial and can’t figure out the problem.

Here is the code I have

I’m very new at this and could use all the help I can get

please post the code directly between 3~
Then it will be esaier to help you.

Is that what you wanted jmv38?

How to post code in the forums:

@alexnvu welcome to the forums! (The problem with your code is that you have not defined


in setup) EDIT: Sorry, I didn’t see your second picture where you did define imagename.
What exactly is the problem you are experiencing? If you detail the problem people are more likely to help. And again, welcome to the forums! Be sure to post if you have any other problems, but always remember to try and solve them yourself first.

@TheSolderKing I’m trying to be able to grab the image and drag it around. I want to specifically grab the item and not be able to move the image unless I’m touching it and dragging it

@alexnvu Try this.


function setup()
    img=readImage("SpaceCute:Beetle Ship")

function draw()
    background(40, 40, 50)

function touched(t)
    if t.state==BEGAN or t.state==MOVING then
        if t.x>x-50 and t.x<x+50 and t.y>y-50 and t.y<y+50 then

@alexnvu the problem lies with calling spriteSize() outside of setup(). I ran your code and moved

imagename = "SpaceCute:Beetle Ship"
imagesize = vec2(spriteSize(imagename))
imageposition = vec2()

into setup() and then it worked. Oh, and PS thanks for spelling my username correctly, barely anyone does that :stuck_out_tongue:

@TheSolderKing thank you! Very new at this and couldn’t figure that one out.

You’re welcome! Yeah sometimes Codea is a bit odd about running things before setup().