Hello there…
Please watch video to get the clear idea of my problem.
https://www.youtube.com/watch?v=7elycc3YMUE&feature=youtu.be
As you can see in the video, the rocket which come at the top of other two does not move to desired position. The all rockets are added to physics and this problem is caused.
When I don’t add these rockets to physics, they move to desired positions on tap and there is no problem…but when I add them to physics they does not move at all.
Also this happens only to rocket which is at top of other two. The bottom rockets to move, though they are added to physics…
Tried to solve myself, but getting confused…
here’s the code…
local physics = require "physics" physics.start() physics.setGravity(0,0) local imgNum = math.random( 1, 16 ) local fileName = "s" .. imgNum .. ".png" local background = display.newImageRect(fileName, display.actualContentWidth, display.actualContentHeight) background.x = display.contentCenterX background.y = display.contentCenterY background.fileName = fileName print(fileName) local rect = display.newRect(240,100,140,500) rect.alpha = .5 local line = display.newImageRect("sl.png",5,600) line.x = 240 line.y = 280 line:setFillColor(0) line.alpha = .5 local line = display.newImageRect("sl.png",10,600) line.x = 180-12 line.y = 280 line:setFillColor(0) line.alpha = 1 local line = display.newImageRect("sl.png",10,600) line.x = 300+12 line.y = 280 line:setFillColor(0) line.alpha = 1 local bluerk = display.newImageRect("bluerk.png", 25, 25) bluerk.x = 205 bluerk.y = 250 bluerk.xScale = 2 bluerk.yScale = 2 bluerk.surfaceType = "rect1" physics.addBody(bluerk,"static") bluerk.isSensor = true local greenrk = display.newImageRect("greenrk.png", 25, 25) greenrk.x =185 greenrk.y = 280 physics.addBody(greenrk,"static") greenrk.surfaceType = "rect11" greenrk.isSensor = true local redrk = display.newImageRect("redrk.png", 25, 25) redrk.x =225 redrk.y = 280 physics.addBody(redrk,"static") redrk.surfaceType = "rect111" redrk.isSensor = true local sheet1 = graphics.newImageSheet( "fire1.png", { width=(960/5), height=(768/4), numFrames=19 } ) local bluefire = display.newSprite( sheet1, { start=5, count=10, time=1000 } ) bluefire.x = 205 bluefire.y = 285 bluefire.xScale = -.18 bluefire.yScale = .15 bluefire:setFillColor(0.2,.2,.8) bluefire:play() bluefire:rotate(180) local sheet1 = graphics.newImageSheet( "fire1.png", { width=(960/5), height=(768/4), numFrames=19 } ) local greenfire = display.newSprite( sheet1, { start=5, count=10, time=1000 } ) greenfire.x = 185 greenfire.y = 302 greenfire.xScale = -.18 greenfire.yScale = .15 greenfire:setFillColor(0.1,.8,.2) greenfire:play() greenfire:rotate(180) local sheet1 = graphics.newImageSheet( "fire1.png", { width=(960/5), height=(768/4), numFrames=19 } ) local redfire = display.newSprite( sheet1, { start=5, count=10, time=1000 } ) redfire.x = 225 redfire.y = 302 redfire.xScale = -.18 redfire.yScale = .15 redfire:setFillColor(0.8,.2,.2) redfire:play() redfire:rotate(180) local function swipeOk(self,event) if (self.x == 205) then transition.moveTo(self, { x=225, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif (self.x == 225) then transition.moveTo(self, { x=185, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif(self.x == 185) then transition.moveTo(self, { x=205, y=250, time=500 } ) self.xScale =2 self.yScale = 2 elseif (self.x == 275) then transition.moveTo(self, { x=295, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif (self.x == 295) then transition.moveTo(self, { x=255, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif(self.x == 255) then transition.moveTo(self, { x=275, y=250, time=500 } ) self.xScale =2 self.yScale = 2 end end local function ok() bluerk.enterFrame = swipeOk Runtime:addEventListener("enterFrame",bluerk) greenrk.enterFrame = swipeOk Runtime:addEventListener("enterFrame",greenrk) redrk.enterFrame = swipeOk Runtime:addEventListener("enterFrame",redrk) end local function pl() bluerk.enterFrame = swipeOk Runtime:removeEventListener("enterFrame",bluerk) greenrk.enterFrame = swipeOk Runtime:removeEventListener("enterFrame",greenrk) redrk.enterFrame = swipeOk Runtime:removeEventListener("enterFrame",redrk) end local function swipeOkk(self,event) if (self.x == 205) then transition.moveTo(self, { x=185, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif (self.x == 185) then transition.moveTo(self, { x=225, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif(self.x == 225) then transition.moveTo(self, { x=205, y=250, time=500 } ) self.xScale =2 self.yScale = 2 elseif (self.x == 275) then transition.moveTo(self, { x=255, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif (self.x == 255) then transition.moveTo(self, { x=295, y=280, time=500 } ) self.xScale = .8 self.yScale = .8 elseif(self.x == 295) then transition.moveTo(self, { x=275, y=250, time=500 } ) self.xScale =2 self.yScale = 2 end end local function okk() bluerk.enterFrame = swipeOkk Runtime:addEventListener("enterFrame",bluerk) greenrk.enterFrame = swipeOkk Runtime:addEventListener("enterFrame",greenrk) redrk.enterFrame = swipeOkk Runtime:addEventListener("enterFrame",redrk) end local function pll() bluerk.enterFrame = swipeOkk Runtime:removeEventListener("enterFrame",bluerk) greenrk.enterFrame = swipeOkk Runtime:removeEventListener("enterFrame",greenrk) redrk.enterFrame = swipeOkk Runtime:removeEventListener("enterFrame",redrk) end local function move(self,event) if (self.y == 250 and self.x == 205 ) then transition.moveTo(self, { x=275, y= 250, time=500 } ) print(self.surfaceType) elseif (self.y == 280 and self.x == 185) then transition.moveTo(self, { x=255, y= 280, time=500 } ) elseif (self.y == 280 and self.x == 225) then transition.moveTo(self, { x=295, y= 280, time=500 } ) elseif (self.y == 250 and self.x == 275 ) then transition.moveTo(self, { x=205, y= 250, time=500 } ) elseif (self.y == 280 and self.x == 255) then transition.moveTo(self, { x=185, y= 280, time=500 } ) elseif (self.y == 280 and self.x == 295) then transition.moveTo(self, { x=225, y= 280, time=500 } ) elseif (self.y == 285 and self.x == 205) then transition.moveTo(self, { x=275, y= 285, time=500 } ) elseif (self.y == 302 and self.x == 185) then transition.moveTo(self, { x=255, y= 302, time=500 } ) elseif (self.y == 302 and self.x == 225) then transition.moveTo(self, { x=295, y= 302, time=500 } ) elseif (self.y == 285 and self.x == 275) then transition.moveTo(self, { x=205, y= 285, time=500 } ) elseif (self.y == 302 and self.x == 255) then transition.moveTo(self, { x=185, y= 302, time=500 } ) elseif (self.y == 302 and self.x == 295) then transition.moveTo(self, { x=225, y= 302, time=500 } ) end end local function okkp() bluerk.enterFrame = move Runtime:addEventListener("enterFrame",bluerk) greenrk.enterFrame = move Runtime:addEventListener("enterFrame",greenrk) redrk.enterFrame = move Runtime:addEventListener("enterFrame",redrk) bluefire.enterFrame = move Runtime:addEventListener("enterFrame",bluefire) greenfire.enterFrame = move Runtime:addEventListener("enterFrame",greenfire) redfire.enterFrame = move Runtime:addEventListener("enterFrame",redfire) end local function pllp() bluerk.enterFrame = move Runtime:removeEventListener("enterFrame",bluerk) greenrk.enterFrame =move Runtime:removeEventListener("enterFrame",greenrk) redrk.enterFrame = move Runtime:removeEventListener("enterFrame",redrk) bluefire.enterFrame = move Runtime:removeEventListener("enterFrame",bluefire) greenfire.enterFrame =move Runtime:removeEventListener("enterFrame",greenfire) redfire.enterFrame = move Runtime:removeEventListener("enterFrame",redfire) end local beginX local beginY local endX local endY local xDistance local yDistance function checkSwipeDirection() xDistance = math.abs(endX - beginX) yDistance = math.abs(endY - beginY) if xDistance \> yDistance then if beginX \> endX then okk() gametimer = timer.performWithDelay(500,pll,1) else ok() gametimer = timer.performWithDelay(500,pl,1) end else if beginY \> endY then else okkp() gametimer = timer.performWithDelay(500,pllp,1) end end end function swipe(event) if event.phase == "began" then beginX = event.x beginY = event.y end if event.phase == "ended" then endX = event.x endY = event.y checkSwipeDirection(); end end Runtime:addEventListener("touch", swipe)