Hello,
I’ve been building my app, and i have run into a few problems. I have split the screen into two buttons, the left button moves the ball to the left and the right button moves it right, and when both buttons are pressed at the same time it changes the gravity. Now for the problems, I have noticed that when you hold either of the buttons down for 15-20 seconds when the ball is in the corner, the ball freezes and the gravity cannot be changed either. Also, if you hold the ball in the corner for a few seconds you can still move the ball, but you cannot change the gravity. I have searched and tried all of the suggestions that i have found, but none have fixed my problem. I hope I have explained my situation well enough. Any help would be GREATLY appreciated!
[lua]_W = display.contentWidth;
_H = display.contentHeight;
–Hide Status Bar
display.setStatusBar(display.HiddenStatusBar);
system.activate( “multitouch” )
local physics = require (“physics”);
physics.start();
physics.setGravity(-9.8 , 0);
physics.setDrawMode(“debug”);
physics.setVelocityIterations( 6 )
–Variables
local touchingGround = false;
–Display Walls----------------------------------------------------------------
local rect_1 = display.newRect(0,0,10,250);
rect_1:setFillColor(255,0,0,255);
rect_1.x = 166;
rect_1.y = 90;
rect_1.rotation = 90;
rect_1.type = “wall1”;
physics.addBody(rect_1, “static”, {friction = 10, densiy = 1});
local rect_2 = display.newRect(0,0,10,348);
rect_2:setFillColor(255,0,0,255);
rect_2.x = 45;
rect_2.y = 259;
rect_2.type = “wall”;
physics.addBody(rect_2, “static”, {friction = 10, density = 1});
local rect_3 = display.newRect(0,0,10,154);
rect_3:setFillColor(255,0,0,255);
rect_3.x = 120;
rect_3.y = 428;
rect_3.rotation = 90;
rect_3.type = “wall1”;
physics.addBody(rect_3, “static”, {friction = 10, density = 1});
local rect_4 = display.newRect(0,0,10,107);
rect_4:setFillColor(255,0,0,255);
rect_4.x = 193;
rect_4.y = 376;
rect_4.type = “wall”;
physics.addBody(rect_4, “static”, {friction = 10, density = 1});
local rect_5 = display.newRect(0,0,10,226);
rect_5:setFillColor(255,0,0,255);
rect_5.x = 285;
rect_5.y = 210;
rect_5.type = “wall”;
physics.addBody(rect_5, “static”, {friction = 10, density = 1});
local rect_6 = display.newRect(0,0,10,102);
rect_6:setFillColor(255,0,0,255);
rect_6.x = 239;
rect_6.y = 319;
rect_6.rotation = 90;
rect_6.type = “wall1”;
physics.addBody(rect_6, “static”, {friction = 10, density = 1});
–Display Ball
local ball = display.newCircle(0, 0, 10);
ball.x = _W * 0.5; ball.y = _H * 0.5;
ball.type = “ball”;
physics.addBody( ball, “dynamic”, {density = 1, radius = 10, friction = 10, bounce = 0.3, filter = ballFilter});
ball.isAwake = true
ball.isSleepingAllowed = false;
ball.angularDamping = 15;
----MultiTouch
local function Button( event )
local phase = event.phase
if “began” == phase then
trigger = true;
function moveR ()
ball:applyForce( 0, -8, ball.x, ball.y)
end
Runtime:addEventListener(“enterFrame”, moveR)
if trigger == true and trigger2 == true then
if(touchingGround == true) then
physics.setGravity(-gx, gy);
end
end
elseif “ended” == phase or “cancelled” == phase then
trigger = false;
Runtime:removeEventListener(“enterFrame”, moveR);
end
end
local function Button2( event )
local phase = event.phase
if “began” == phase then
trigger2 = true;
function moveL ()
ball:applyForce( 0, 8, ball.x, ball.y)
end
Runtime:addEventListener(“enterFrame”, moveL)
if trigger == true and trigger2 == true then
if(touchingGround == true) then
physics.setGravity(-gx, gy);
end
end
elseif “ended” == phase or “cancelled” == phase then
trigger2 = false;
Runtime:removeEventListener(“enterFrame”, moveL);
end
end
button = display.newRect( 0, 0, _W, _H * 0.5 )
button.x = _W * 0.5;
button.y = 120;
button:setFillColor(0, 0, 0, 0)
button:addEventListener( “touch”, Button )
button2 = display.newRect( 0, 0, _W, _H * 0.5 )
button2.x = _W * 0.5;
button2.y = 360;
button2:setFillColor(0, 0, 0, 0)
button2:addEventListener( “touch”, Button2 )
--------Update Gravity
function update (event)
gx, gy = physics.getGravity()
end
timer.performWithDelay(10, update, 0);
–Collision Filter
function onCollision( event )
if ( event.phase == “began” ) then
if(event.object1.type == “wall” and event.object2.type == “ball”) then
touchingGround = true;
end
elseif ( event.phase == “ended” ) then
touchingGround = false
end
end
Runtime:addEventListener( “collision”, onCollision )
[import]uid: 17138 topic_id: 12285 reply_id: 312285[/import]