我想在Corona中更改drawMode。只有当身体在开始时落在地上时它才有效。当身体躺在地上时,我无法改变drawMode。有人可以帮我吗?这是带有onKeyEvent函数的代码。
local physics = require "physics"
function onKeyEvent( event )
if (event.keyName == "d") then
physics.setDrawMode( "debug" );
end
if (event.keyName == "n") then
physics.setDrawMode( "normal" );
end
if (event.keyName == "h") then
physics.setDrawMode( "hybrid" );
end
end
Runtime:addEventListener( "key", onKeyEvent );
physics.start();
physics.setScale( 60 )
physics.setGravity( 0, 9.8 ) -- initial gravity points downwards
local groundIm = display.newRect(0, 400, 320, 20);
groundIm:setFillColor(255, 255, 255);
local ground = physics.addBody(groundIm, "static", {friction = 0.5});
local boxIm = display.newRect(100,100,30,30);
boxIm:setFillColor(0, 0, 255);
local triangleShape = { 0,-35, 37,30, -37,30 };
local body = physics.addBody(boxIm, "dynamic", {shape = triangleShape});
答案 0 :(得分:0)
只需添加这行代码,一切都应该正常工作
boxIm.isSleepingAllowed = false