Search code examples
luacoronasdk

Changing drawMode with setDrawMode in Corona


I want to change drawMode in Corona. It works only when the body is falling on the ground at the beginning. I can't change drawMode when the body is lying on the ground. Could someone help me pls? Here is the code with onKeyEvent function.

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});

Solution

  • Just add this line of code and everything should work

    boxIm.isSleepingAllowed = false