Hi All
Although new to corona I have worked on Android SDK before and also various other languages (mainly as a hobbyist though).
Currently I have been starting with some basic parts of corona such as even listeners, drawing circles, making objects move by touch and linear impulse etc.
Now, I have started with joints, more so with the rope joint. Currently my basic project draws a Rec object across the top of the screen and then a joint links this to a circle object. I then have an event listener which then when the circle is pulled on, it makes the circle move swinging via the joint.
However this is all in the portrait display and I wanted to then rotate the display to landscape left or right and have the rect object expand across the screen and the joint to be centred as it has been in portrait.
My way of doing this probably is not necessarily the “right” way which could be the cause of my problem. I have tried both an onOrientationChange function and also a onResize function but every time the device is rotated, the joint either lost or if I try and re-create it by doing a removeself() or display.remove(joint) and then do a joint = nil and then create it again, the simulator locks up
My code is very rough around the edges and I have tried so much to get this to work that I have probably forgotten what I have done now.
Also I know I am not checking for what type of orientation has occurred in the function from the code but I did also add an if statement in as well. This was removed so I could see what would happen no matter what orientation was set.
here is my code :
local gamephysics = require ("physics") gamephysics.start() gamephysics.setDrawMode("hybrid") local leftSide = display.screenOriginX; local rightSide = display.contentWidth-display.screenOriginX; local topSide = display.screenOriginY; local bottomSide = display.contentHeight-display.screenOriginY; print (display.contentWidth) print (display.actualContentWidth) print (display.viewableContentWidth) -- tried using this but a joint cannot be part of a group objectgroup = display.newGroup() ceiling = display.newRect(objectgroup,0,0,leftSide +rightSide,20) ceiling.x = leftSide +10+display.contentWidth\*0.5 ceiling.y = topSide + 100 gamephysics.addBody(ceiling,"static", {density = 1.0 , friction = 0.3 ,bounce = 0.2}) player = display.newCircle(objectgroup,0,0,100) player.x , player.y = display.contentCenterX, 450 gamephysics.addBody(player,"dynamic", {density=1.0 , friction= 0.3 ,bounce=0.2,radius=30}) startposx = player.x startposy = player.y joint = gamephysics.newJoint("rope",ceiling,player,0,0,0,0) joint.maxLength = 780 -- ceiling.y = 1080 -- ceiling.x,ceiling.y = display.contentCenterX,860 function pullRelease(event) if (event.phase == "began") then display.getCurrentStage():setFocus(player) elseif (event.phase == "ended") then player:applyLinearImpulse(event.xStart - event.x,event.yStart - event.y,player.x,player.y) display.getCurrentStage():setFocus(nil) transition.to (player, {time=1500,x=(startposx),y=(startposy),delay=10000}) end end function switchSides(event) -- ceiling.rotation = ceiling.rotation - event.delta; leftSide = display.screenOriginX; rightSide = display.contentWidth-display.screenOriginX; topSide = display.screenOriginY; bottomSide = display.contentHeight-display.screenOriginY; ceiling:removeSelf() ceiling = display.newRect(0,0,leftSide +rightSide,20) ceiling.x = leftSide +10+display.contentWidth\*0.5 ceiling.y = topSide + 100 player:removeSelf() player = display.newCircle(0,0,100) player.x , player.y = display.contentCenterX, 450 gamephysics.addBody(player,"dynamic", {density=1.0 , friction= 0.3 ,bounce=0.2,radius=30}) startposx = player.x startposy = player.y joint.maxLength = 780 -- joint:remove(joint) -- joint = nil; -- local landorport = event.name -- if landorport == "resize" then -- leftSide = display.screenOriginX; -- rightSide = display.contentWidth-display.screenOriginX; -- topSide = display.screenOriginY; -- bottomSide = display.contentHeight-display.screenOriginY; -- ceiling = display.newRect(0,0,leftSide +rightSide,20) -- ceiling.x = leftSide +10+display.contentWidth\*0.5 -- ceiling.y = topSide + 100 -- -- -- --joint = gamephysics.newJoint("rope",ceiling,player,0,0,0,0) -- -- end end player:addEventListener("touch",pullRelease)Runtime:addEventListener("orientation", switchSides )
Thanks
TimCS
). 