0

我希望我的小鸟在这里玩耍时上下运动是我的代码

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

这段代码只是从右到左我希望我的鸟在它向左移动时上下移动有人可以帮助我吗?

4

1 回答 1

2

这是一个示例。尝试这个:

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)

继续编码............ :)

于 2013-08-12T10:33:36.720 回答