Hi everybody. First of all im very very newbie in corona and lua and my english are terrible
i would like to make topview race game but i dont know what to do to start a car and make a lap in a single track. I use transition and linearVelocity. i use this code for a sample and make some changes but the car go to a straight line and not turn.
[lua]W = display.contentWidth
H = display.contentHeight
print(W)
print(H)
physics = require (“physics”)
physics.start()
system.activate(“multitouch”);
local track = display.newImageRect(“track.png”,2048,2048)
track:setReferencePoint(display.CenterReferencePoint)
track.x = W/2*4.2
track.y = H/2
physics.addBody(track,“dynamic”,{density=.5, friction = 1})
local car = display.newImageRect(“yellowcar.png”,90,140)
car:setReferencePoint(display.CenterReferencePoint)
car.x = W/2
car.y = H/2
local up = display.newImage(“upx.png”);
up.x = 440; up.y = 750;
local left = display.newImage(“leftx.png”);
left.x = 40 ; left.y = 750;
local right = display.newImage(“rightx.png”);
right.x = 95; right.y = 750;
local motionx = 0;
local function stop (event)
if(event.phase == “ended”) then
motionx = 0;
end
end
Runtime:addEventListener(“touch”, stop );
function left:touch()
motionx = 5;
end
left:addEventListener(“touch”, left);
function right:touch()
motionx = -5;
end
right:addEventListener(“touch”, right);
function moveTrack(event)
track.x = track.x + motionx
track.y = track.y + motionx
end
Runtime:addEventListener(“enterFrame”, moveTrack);
function moveCar(event)
track:setLinearVelocity(0,0)
–transition.to( track, { time=1500, alpha=1, x=(W/2*4.2), y=(1000) } )
end
up:addEventListener(“tap”, moveCar);[/lua] [import]uid: 209841 topic_id: 34495 reply_id: 334495[/import]