我有多个对象和多个容器,我的计划是任何对象都可以放在任何容器上,但是一旦容器上有一个对象放在上面,我希望它被占用并且不允许更多的对象放在上面。是否有 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
这是我的代码,另外我有一个附加到每个图块的值,例如图块 a =“A”,目前我只是在每次移动图块时附加一个字符串,但我想要字符串或者可能使用仅在将图块放入容器中时附加表。例如,如果一个字母在错误的位置,而我将它移动到正确的位置,我已经触摸了两次,所以我的最终字符串将是错误的