简体   繁体   English

使用翻译电晕sdk进行上下敌人运动

[英]Up and Down Enemy Movement using translate corona sdk

i want my bird to have a up and down movement when it plays here is my code 我希望我的小鸟在这里播放时可以进行上下移动是我的代码

function updateMons2()
      for a = 1, mons2.numChildren, 1 do
        physics.addBody(mons2[a],"kinematic")
          if(mons2[a].isAlive == true) then
              (mons2[a]):translate(speed * -1, 0)            

              if(mons2[a].x < -80) then
                  mons2[a].x = 1000
                  mons2[a].y = 500
                  mons2[a].isAlive = false 
              end
          end
      end
  end

this code only does is from right to left i want my bird to move up and down while it is going left can someone help me? 这个代码只是从右到左我希望我的鸟在它离开时上下移动有人可以帮助我吗?

Here is a sample. 这是一个例子。 try this: 尝试这个:

local mons2 = {}
local yPos = {}
for i=1,2 do
  mons2[i] = display.newImageRect("1.png",50,50)
  mons2[i].x = 100
  mons2[i].y = 100+(100*(i-1))
  mons2[i].isAlive = true
  yPos[i] = mons2[i].y
end

speed = 10
count_ = 0
function updateMons2()
  count_ = count_ + 1
  for a = 1, 2, 1 do
    physics.addBody(mons2[a],"kinematic")
     if(mons2[a].isAlive == true) then
       mons2[a]:translate(speed * -1, 0)
       transition.to(mons2[a],{time=50,y=yPos[a]+(20*(count_%2)*-1)})
         if(mons2[a].x < -80) then
           mons2[a].x = 350
         end
     end
  end
end
timer.performWithDelay(100,updateMons2,-1)

Keep Coding........... :) 保持编码........... :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM