Thanks so much for the help so far. I am creating a word game. I break up the letters into individual sprites and the accompanying physics object. I then drag them around to “slots”. Once they hit their slot, I would like to remove them. I am using collision detection to get this done. THe problem I have is that when I have a word with the same letters like gOOse, it removes both sprites when I collide with one of the letters “letter[e] = nil” removes both Os in one go.
for z=1,#new_word do -- create 5 objects
letter[z] =readImage("Dropbox:"..characters[z])
letter_diam=(letter[z].width+letter[z].height)/2
rande_x = math.random(200,514)
rande_y = math.random(150,268)
rando_x = math.random(514,824)
rando_y = math.random(500,618)
if (z % 2 ~= 0) then
table.insert(tab,vec2(rande_x,rande_y))
-- Create the physics objects --
p_letter[z] = physics.body(CIRCLE,letter_diam/2)
p_letter[z].x = rande_x
p_letter[z].y = rande_y
p_letter[z].info=characters[z]
else
table.insert(tab,vec2(rando_x,rando_y))
-- Create the physics objects --
p_letter[z] = physics.body(CIRCLE,letter_diam/2)
p_letter[z].x = rando_x
p_letter[z].y = rando_y
p_letter[z].info=characters[z]
end
end
for z1=1,#new_word do -- create 5 objects
target[z1] =readImage("Dropbox:"..characters[z1])
table.insert(tab1,vec2(x_loc,rh/2))
table.insert(tab_orig,vec2(x_loc,rh/2))
-- Create the physics objects --
p_target[z1] = physics.body(CIRCLE,letter_diam/2)
p_target[z1].x = x_loc
p_target[z1].y = rh/2
p_target[z1].info="t"..characters[z1]
x_loc=x_loc+100
end
function collide(contact)
if contact.state == BEGAN then
if "t"..contact.bodyA.info==contact.bodyB.info then
print(contact.bodyA.info)
print("hit")
for e,f in pairs(tab_orig) do
done=0
if contact.bodyA.info == characters[e] and done ==0 then
letter[e] = nil
print("done")
done=1
break
end
end
end
end
end