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. https://m.youtube.com/watch?v=B3k0saVH5uA

Here is the code I have
http://imgur.com/uHj09ll
http://imgur.com/PzpX96T

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.

http://imgur.com/lHAeySm

Is that what you wanted jmv38?

How to post code in the forums:

http://codea.io/talk/discussion/275/faq-please-read#latest

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

imagename

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.


displayMode(FULLSCREEN)

function setup()
    img=readImage("SpaceCute:Beetle Ship")
    x=WIDTH/2
    y=HEIGHT/2
end

function draw()
    background(40, 40, 50)
    sprite(img,x,y,100)
end

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
            x=t.x
            y=t.y
        end
    end
end

@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().