2014-01-14 25 views
0

我想製作一個像着名的點:一個關於連接的遊戲,在這裏你必須連接相同顏色的點。我的問題在於畫線。它必須是直的,並從一個點(物理對象)開始,並捕捉到另一個相同顏色的點。如果你能幫助我理解如何繪製一條直線來捕捉另一個物體,那將是非常值得讚賞的。Corona SDK。通過畫一條直線連接兩個物理實體

回答

0

你不需要這條線來捕捉,你只需要它看起來像是捕捉。

CoronaSDK有一種繪製線條的方法,另一種繪製矩形。

display.newLine([parentGroup,], x1, y1, x2, y2) 
display.newRect(left, top, width, height) 

您可以使用最喜歡的任何一個。

local originX  -- the X coordinate where the line starts 
local originY  -- the Y coordinate where the line starts 
local finalX  -- the X coordinate where the line ends 
local finalY  -- the Y coordinate where the line ends 
local parentGroup -- the line's parent group 
local rectWidth -- the rect's width (this is the distance between originX and finalX) 
local rectHeight -- the rect's height 

--with newLine 
local line = display.newLine(parentGroup, originX, originY , finalX, finalY) 

--with newRect 
local line = display.newRect(parentGroup, originX, originY , rectWidth, rectHeight) 
line:setReferencePoint(display.CenterLeftReferencePoint) -- draws the line from the left