Corona:无法在屏幕触摸时使实例“跳跃”。

尝试让一个精灵(instance1)在触摸时跳跃,但它不起作用。

这是我的代码:

physics.addBody( instance1, { density=1.0, friction=0.3, bounce=0.3} )
local function jump( event )
  if(event.numTaps == 2) then

    instance1:applyForce( 350, -2000, instance1.x, instance1.y )
  end
end

instance1:addEventListener("tap", jump)

我要补充一点,如果我这样做,精灵实例会跳跃一次,但不会再次跳跃:

local function jump( event )
  if(event.numTaps == 2) then
    physics.addBody( instance1, { density=1.0, friction=0.3, bounce=0.3} )
    instance1:applyForce( 350, -2000, instance1.x, instance1.y )
  end
end

instance1:addEventListener("tap", jump)

实例信息:

local sheet1 = sprite.newSpriteSheet( "character.png", 75, 105 )

local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 16)

sprite.add( spriteSet1, "character", 1, 12, 700, 1 ) -- play 12 frames every 700 ms

local instance1 = sprite.newSprite( spriteSet1 )

instance1.x = display.contentWidth/2
instance1.y = 240

原文链接 https://stackoverflow.com/questions/9086053

点赞
stackoverflow用户909233
stackoverflow用户909233

还是无法重现你的错误,

我回答了你的问题,让你粘贴我测试的代码:

--main.lua
local sprite=require("sprite")
local physics=require("physics")

local sheet1 = sprite.newSpriteSheet( "character.png", 75, 105 )

local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 16)

sprite.add( spriteSet1, "character", 1, 12, 700, 1 ) -- 每 700 毫秒播放 12 帧

local instance1 = sprite.newSprite( spriteSet1 )

instance1.x = display.contentWidth/2
instance1.y = 240

physics.start()
physics.setGravity(0,1)
physics.addBody( instance1, { density=1.0, friction=0.3, bounce=0.3} )
local function jump( event )
  if(event.numTaps == 2) then

    instance1:applyForce( 35, -200, instance1.x, instance1.y )
  end
end

instance1:addEventListener("tap", jump)
2012-02-02 01:23:47