Drag lagging on iOS 7

I finally have my game out… but there’s a bug I couldn’t figure out how to fix, and I was wondering if you guys can take a look and tell me what you think

If you get my game, just play a few rounds and you’ll notice that, sometimes, the character that you control dragging left and right will lag. Sometimes the drag is really smooth, and sometimes is very choppy.

Link: https://itunes.apple.com/us/app/finger-boing-free/id728175134?mt=8

That only happens on iOS 7, on any earlier version the controls were always smooth.

I’ve gone crazy trying all I could, but it’s been impossible to find out what can be causing such a random behavior.

This is the code that does the dragging:

 function bgcolor:touch( event ) if (gameRunning == false and dead == false and showingTutorial == false) then startGame() end if (dead == false and showingTutorial == false) then if event.phase == "began" then display.getCurrentStage():setFocus( self, event.id ) self.isFocus = true elseif self.isFocus then if event.phase == "moved" then local myx = (event.x) gameBombController.x = myx gameBomb.x = myx elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus( self, nil ) self.isFocus = false end end end return true end

I’d really appreciate if you guys can get the game (free) and take a look to get some fresh ideas.

Thank you very much

I’ve made a clean project to reproduce the issue.

Build and run this code on an iPhone 5 with iOS 7.

Just open the app, drag a few times the grey ball left and right, press the home button to close, and repeat.

You’ll see that sometimes the ball drags smoothly, and some others it lags and has some choppy movement.

If you comment this line the issue stops happening and everything works fine:

Runtime:addEventListener( “enterFrame”, animateBG );

This code is similar to the one in my game, except that if I comment that line (it makes the BG spin), I still hit the same issue, so there has to be something else making it happen.

With this project you can at least reproduce it and explore.

main.lua:

local launchArgs = ... local widget = require "widget" dWidth = display.contentWidth dHeight = display.contentHeight function initBG() bg = display.newRect(0,0,256,256) bg:setFillColor(0,0,0) bg.x = dWidth/2 bg.y = dHeight\*1.1 bg.xScale = 2.2 bg.yScale = 2.2 bg.alpha = 0.2 currentBGspeed = 0.1 function animateBG(event) bg:rotate(currentBGspeed) end -- Comment the next line to avoid hitting the issue Runtime:addEventListener( "enterFrame", animateBG ); end function initBGcolor() bgcolor = display.newRect(0,0,dWidth,dHeight) bgcolor.x = dWidth / 2 bgcolor.y = dHeight / 2 bgcolor:setFillColor(1,1,1) -- touch listener for bg function bgcolor:touch( event ) if event.phase == "began" then display.getCurrentStage():setFocus( self, event.id ) self.isFocus = true elseif self.isFocus then if event.phase == "moved" then local x = (event.x) circle.x = x elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus( self, nil ) self.isFocus = false end end return true end bgcolor:addEventListener( "touch", bgcolor ) end circle = display.newCircle(dWidth / 2, dHeight / 2, 32) circle:setFillColor(0.5,0.5,0.5) initBGcolor() initBG() circle:toFront()

config.lua:

application = { content = { width = 320 \* (display.pixelHeight/display.pixelWidth\>1.5 and 1 or 1.5/(display.pixelHeight/display.pixelWidth)), height = 480 \* (display.pixelHeight/display.pixelWidth\<1.5 and 1 or (display.pixelHeight/display.pixelWidth)/1.5), scale = "letterbox", imageSuffix = { ["-hd"] = 1.5, }, fps = 60, }, }

build.settings

settings = { orientation = { default = "portrait", }, iphone = { plist= { UIApplicationExitsOnSuspend=true, }, }, }

I’ve made a clean project to reproduce the issue.

Build and run this code on an iPhone 5 with iOS 7.

Just open the app, drag a few times the grey ball left and right, press the home button to close, and repeat.

You’ll see that sometimes the ball drags smoothly, and some others it lags and has some choppy movement.

If you comment this line the issue stops happening and everything works fine:

Runtime:addEventListener( “enterFrame”, animateBG );

This code is similar to the one in my game, except that if I comment that line (it makes the BG spin), I still hit the same issue, so there has to be something else making it happen.

With this project you can at least reproduce it and explore.

main.lua:

local launchArgs = ... local widget = require "widget" dWidth = display.contentWidth dHeight = display.contentHeight function initBG() bg = display.newRect(0,0,256,256) bg:setFillColor(0,0,0) bg.x = dWidth/2 bg.y = dHeight\*1.1 bg.xScale = 2.2 bg.yScale = 2.2 bg.alpha = 0.2 currentBGspeed = 0.1 function animateBG(event) bg:rotate(currentBGspeed) end -- Comment the next line to avoid hitting the issue Runtime:addEventListener( "enterFrame", animateBG ); end function initBGcolor() bgcolor = display.newRect(0,0,dWidth,dHeight) bgcolor.x = dWidth / 2 bgcolor.y = dHeight / 2 bgcolor:setFillColor(1,1,1) -- touch listener for bg function bgcolor:touch( event ) if event.phase == "began" then display.getCurrentStage():setFocus( self, event.id ) self.isFocus = true elseif self.isFocus then if event.phase == "moved" then local x = (event.x) circle.x = x elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus( self, nil ) self.isFocus = false end end return true end bgcolor:addEventListener( "touch", bgcolor ) end circle = display.newCircle(dWidth / 2, dHeight / 2, 32) circle:setFillColor(0.5,0.5,0.5) initBGcolor() initBG() circle:toFront()

config.lua:

application = { content = { width = 320 \* (display.pixelHeight/display.pixelWidth\>1.5 and 1 or 1.5/(display.pixelHeight/display.pixelWidth)), height = 480 \* (display.pixelHeight/display.pixelWidth\<1.5 and 1 or (display.pixelHeight/display.pixelWidth)/1.5), scale = "letterbox", imageSuffix = { ["-hd"] = 1.5, }, fps = 60, }, }

build.settings

settings = { orientation = { default = "portrait", }, iphone = { plist= { UIApplicationExitsOnSuspend=true, }, }, }