2012-02-10 1 views
0

공이 Ractangle에 뛰어 들었을 때 공의 이동을 방지하는 데 문제가 있습니다. 사각형은 일정한 속도로 왼쪽으로 이동합니다. 공이 화면을 따라갑니다. 공이 사각형 위로 점프하면 사각형이 떨어지는 속도를 얻습니다. Pleace 도움!Corona sdk가 공의 x 이동을 방지합니다

--make a box 
local box1 = display.newRect(600, 220, 20, 20) 
box1:setFillColor(255,255,255) 
physics.addBody(box1, "static", { friction=0, bounce=0.0 }) 

-- make a ball (off-screen) and position it 
local ball = display.newImage("ball.png", 20, 20) 
ball.x, ball.y = 100, 200 


-- add physics to the ball 
physics.addBody(ball, { density = 1.0, friction = 0, bounce = 0, radius = 19 }) 

--rotate the ball 
local function rotateBall() 
ball.rotation = -365 
transition.to(ball, { time=1000, rotation=365, onComplete=rotateBall}) 

end 
rotateBall() 

답변

0

내가 당신에게 왕복 방향

  • 메이크업에 무한 회전 계속 공을 만들기 위해 노력하고 올바르게

    • 을 이해한다면 : 여기

      내 코드의 일부입니다 공 바운스

    아래의 코드는 작동합니다 :

    local physics=require("physics") 
    physics.start() 
    
    --make a box 
    local box1 = display.newRect(50, 420, 150, 150) 
    box1:setFillColor(255,255,255) 
    physics.addBody(box1, "static", { friction=0, bounce=0.0 }) 
    
    -- make a ball (off-screen) and position it 
    local ball = display.newImage("scnGame_bird.png", 20, 20) 
    ball.x, ball.y = 100, 200 
    
    
    -- add physics to the ball 
    physics.addBody(ball, { density = 1.0, friction = 0, bounce = 0.8, radius = 19 }) 
    
    --rotate the ball 
    
    --ball.rotation = -365 
    local rotateBallReverse 
    local function rotateBall() 
        transition.to(ball, { time=1000, rotation=365, onComplete=rotateBallReverse}) 
    end 
    
    rotateBallReverse = function() 
        transition.to(ball, { time=1000, rotation=-365, onComplete=rotateBall}) 
    end 
    rotateBall() 
    

    나머지는 'x 움직임 방지'란 무엇을 의미합니까?

  • +0

    미안하지만, 내가 궁금해하는 것이 아닙니다. 내가 한 일은이 있었다 : \t \t -마다의 프레임 요소를 \t 지역 tPrevious = system.getTimer() \t 로컬 함수 이동 (이벤트) \t \t --prevent 속도 /의 움직임을 이동 이벤트 공 \t \t VX, VY = 공 : getLinearVelocity() \t \t \t VX <0 다음 \t \t \t 볼 경우 : setLinearVelocity (0, 0) \t \t \t \t \t 끝 \t \t \t \t 경우 VX> 0 다음 \t \t \t 볼 : setLinearVelocity (0, 0) \t \t \t 끝 \t 끝 \t - \t 런타임을 움직이는 모든 것을 시작하여 addEventListener를 ("enterFrame", move); 각 프레임의 공의 속도가 0보다 크거나 작 으면 다시 0으로 설정됩니다. – Spoeken