0
我有多個對象和多個容器,我的計劃是任何對象都可以放在任何容器上,但是一旦容器上有一個對象,我想讓它被佔用,不允許有更多的對象。有一個isOcuppied電話或類似的東西,我找不到任何這樣的例子。將對象拖放到容器上並將其標記爲已佔用
local function onTouch(event)
local t = event.target
local phase = event.phase
if "began" == phase then
-- Make target the top-most object
local parent = t.parent
parent:insert(t)
display.getCurrentStage():setFocus(t)
-- Spurious events can be sent to the target, e.g. the user presses
-- elsewhere on the screen and then moves the finger over the target.
-- To prevent this, we add this flag. Only when it's true will "move"
-- events be sent to the target.
t.isFocus = true
-- Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
elseif t.isFocus then
if "moved" == phase then
-- Make object move (we subtract t.x0,t.y0 so that moves are
-- relative to initial grab point, rather than object "snapping").
t.xScale = 1.7
t.yScale = 1.7
t.x = event.x - t.x0
t.y = event.y - t.y0
--t1 = t1..t.value
elseif "ended" == phase or "cancelled" == phase then
for i = 1, #posX do
if (((t.x >= ((sizeX/2) + posX[i] - ((2/3) * sizeX))) and (t.y >= ((sizeY/2) + posY - ((1/3) * sizeY))) and (t.x <= ((sizeX/2) + posX[i] + ((2/3) * sizeX))) and (t.y <= ((sizeY/2) + posY + ((1/3) * sizeY)))) or ((t.x >= ((sizeX/2) + posX[i] - ((1/3) * sizeX))) and (t.y >= ((sizeY/2) + posY - ((2/3) * sizeY))) and (t.x <= ((sizeX/2) + posX[i] + ((1/3) * sizeX))) and (t.y <= ((sizeY/2) + posY + ((2/3) * sizeY)))) or ((t.x >= ((sizeX/2) + posX[i] - ((1/2) * sizeX))) and (t.y >= ((sizeY/2) + posY - ((1/2) * sizeY))) and (t.x <= ((sizeX/2) + posX[i] + ((1/2) * sizeX))) and (t.y <= ((sizeY/2) + posY + ((1/2) * sizeY))))) then
t.x, t.y = posX[i] + (sizeX/2), posY + (sizeY/2);
elseif (((t.x >= ((sizeX/2) + posX1[i] - ((2/3) * sizeX))) and (t.y >= ((sizeY/2) + posY1 - ((1/3) * sizeY))) and (t.x <= ((sizeX/2) + posX1[i] + ((2/3) * sizeX))) and (t.y <= ((sizeY/2) + posY1 + ((1/3) * sizeY)))) or ((t.x >= ((sizeX/2) + posX1[i] - ((1/3) * sizeX))) and (t.y >= ((sizeY/2) + posY1 - ((2/3) * sizeY))) and (t.x <= ((sizeX/2) + posX1[i] + ((1/3) * sizeX))) and (t.y <= ((sizeY/2) + posY1 + ((2/3) * sizeY)))) or ((t.x >= ((sizeX/2) + posX1[i] - ((1/2) * sizeX))) and (t.y >= ((sizeY/2) + posY1 - ((1/2) * sizeY))) and (t.x <= ((sizeX/2) + posX1[i] + ((1/2) * sizeX))) and (t.y <= ((sizeY/2) + posY1 + ((1/2) * sizeY))))) then
t.x, t.y = posX1[i] + (sizeX/2), posY1 + (sizeY/2);
t2[i] = t.value
--t1 = t1..t.value
-- elseif (((t.x >= ((sizeX/2) + posX2 - ((2/3) * sizeX))) and (t.y >= ((sizeY/2) + posY2 - ((1/3) * sizeY))) and (t.x <= ((sizeX/2) + posX2 + ((2/3) * sizeX))) and (t.y <= ((sizeY/2) + posY2 + ((1/3) * sizeY)))) or ((t.x >= ((sizeX/2) + posX2 - ((1/3) * sizeX))) and (t.y >= ((sizeY/2) + posY2 - ((2/3) * sizeY))) and (t.x <= ((sizeX/2) + posX2 + ((1/3) * sizeX))) and (t.y <= ((sizeY/2) + posY2 + ((2/3) * sizeY)))) or ((t.x >= ((sizeX/2) + posX2 - ((1/2) * sizeX))) and (t.y >= ((sizeY/2) + posY2 - ((1/2) * sizeY))) and (t.x <= ((sizeX/2) + posX2 + ((1/2) * sizeX))) and (t.y <= ((sizeY/2) + posY2 + ((1/2) * sizeY))))) then
-- t.x, t.y = posX2 + (sizeX/2), posY2 + (sizeY/2);
end
end
t1 = t1..t.value
t.xScale = 1
t.yScale = 1
--print(tile.label)
display.getCurrentStage():setFocus(nil)
t.isFocus = false
--n = n + 1
--value = " "
end
end
這裏是我的代碼,因爲它的立場,也爲Im我有連接到每個瓷磚如磚一=「A」的值,目前我每次只需追加一個字符串瓦片被移動,但我想要字符串或者可以使用一個表格只在瓷磚放入一個容器時才被添加。例如,如果一個字母是在錯誤的地方,我將其移動到我摸到了兩次正確的地方,所以我最終的字符串將是錯誤的
任何人都可以請幫我解決這個問題嗎?我已經正確地閱讀了單詞或短語,現在我需要的是如何阻止在容器中的另一個之上進行拼貼 – Gooner