I’m working on a garden game for kids… For the first part of the game the kids must pick the weeds out of the ground and toss them. So far in my code I have one picture of a weed in a garden which is attached to a table that tells it to go in different spots. When the weed is tapped a different picture shows up (a weed that has been uprooted)
What I am having trouble with is making the uprooted objects draggable… I have never added a drag event to an image that is connect to a table…Or I guess my case 2 images…
Here is the code I got so far…
[lua]–[[
PROJECT OBJECTIVES
OBJECTIVE 1:
pick weeds and make them appear to be uprooted. Toss them in the trash.
OBJECTIVE 2:
Spreed good seeds to grow
OBJECTIVE 3:
Water plants and watch them grow
]]
display.setStatusBar( display.HiddenStatusBar ) – HIDE STATUS BAR
local loqsprite = require(‘loq_sprite’)
math.randomseed(os.time())
math.random()
local _W = display.contentWidth
local _H = display.contentHeight
local objects = {}
local speed = 5
local i
local x0 , y0, x1, x2
local t1 = {
{ x = 650, y = 365 },
{ x = 350, y = 380 },
{ x = 550, y = 480 },
{ x = 400, y = 550 },
{ x = 700, y = 600 },
}
local background = display.newImageRect(“background.png”, 1024, 768)
background.x = _W/2; background.y = _H/2
function pickMe(event)
local phase = event.phase
local x = event.x
local y = event.y
local target = event.target
local saveX = event.target.x
local saveY = event.target.y
local id = event.target.id
if “began” == phase then
display.currentStage:setFocus(objects[event.target])
target.x0 = x
target.y0 = y
target.isFocus = true
event.target:removeEventListener(“touch”, pickMe)
event.target:removeSelf()
objects[id] = nil
print(“objects”… id)
objects[event.target] = display.newImageRect(“picked.png”, 236, 221)
objects[event.target].x = saveX
objects[event.target].y = saveY
elseif “moved” == phase and target.isFocus==true then
target.x = target.x + (x-target.x0)
target.y = target.y + (y-target.y0)
target.x0 = x
target.y0 = y
elseif “ended” == phase then
display.currentStage:setFocus(nil)
objects[event.target].isFocus = false
target.x0 = nil
target.y0 = nil
end
end
for i = 1,5 do
objects[i] = display.newImageRect(“weed.png”, 200, 150 )
objects[i].x = t1[i].x; objects[i].y = t1[i].y
objects[i].id = i
objects[i]:addEventListener(“touch”, pickMe)
end[/lua]
Thanks for any help!! [import]uid: 51459 topic_id: 17168 reply_id: 317168[/import]
[import]uid: 51459 topic_id: 17168 reply_id: 64636[/import]