1

私はこれをグーグルで試してみましたが、チュートリアルは特定のターゲットへの発射体の遷移を行う方法のみを教えてくれます.私の場合、ターゲットに向かって移動した後、画面の端まで続けます.

これは私の現在の撮影機能です:

local function shoot()
--Invert coordinates 
local x = screenWidth - x
local y = screenHeight - y

--a2+b2=c2
local sqDistance = ((x-centerX)*(x-centerX))+((y-centerY)*(y-centerY)) 
--Sqaure root it.
local dist = mSqrt(sqDistance); 

--speed = d/t
distTime = dist/BULLET_SPEED
--if distTime is negative, this makes it positive
if distTime < 0 then 
    distTime = distTime -distTime -distTime
end 

--Create the bullet
local shot = display.newRect(1,1,6,2)
shot.x = centerX; shot.y = centerY; 
shot:setFillColor(240,200,0)
shot.rotation = angleBetween+90;                        
bulletGroup:insert(shot)

--Remove bullet 
local function removeShot()
    display.remove(shot)
    shot = nil
end     

--Move the bullet
transition.to(shot, {time = distTime, x = x, y = y, onComplete = removeShot})


end
4

2 に答える 2

1

これを行う方法を見つけましたが、残念ながら物理ライブラリを使用する必要があるようです。

箇条書きを作成するときに、次の行を追加します。

physics.addBody(shot,"dynamic") 

箇条書きを移動するには、transition.to の代わりにこれを使用します。

--Move the bullet
local xVelocity = (x-centerX)*BULLET_SPEED
local yVelocity = (y- centerY)*BULLET_SPEED
shot:setLinearVelocity(xVelocity,yVelocity)
于 2013-07-27T22:55:59.137 に答える