Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Timer runs slower on HTML5 builds
Started by gamebit.labs Jan 30 2020 04:36 PM

- - - - -
1 reply to this topic
html5 timer browser
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

gamebit.labs

[GLOBAL: userInfoPane.html]
gamebit.labs
  • Contributor

  • 224 posts
  • Corona SDK

I have a count up and down timer in my puzzle app. The same code runs fine on iOS and Android devices but it runs slower for HTML5 builds. Comparing it with a stopwatch on 30 sec run, my timer is slow by 7-8 secs.

 

What could be wrong? Help needed...

module(...,package.seeall)
print( "FPS: "..display.fps )
local swtimer = {}

-- Init
function swtimer:create()
	
	-- Design Time view
	local view = gv:createGroup(0.5, 0, true)
		--
		local base = display.newImageRect(view,gv.imgdir.."common/other/timer.png",292,91)
		--
		local hourlbl = gv:createText("swtimer",-87,5,nil,nil,nil) ; view:insert(hourlbl) ; view.hourlbl = hourlbl
		hourlbl.text = tostring("00") 
		--
		local seplbl = gv:createText("swtimer",-42,5,nil,nil,nil) ; view:insert(seplbl) ; view.seplbl1 = seplbl
		seplbl.text = ":"
		--
		local minlbl = gv:createText("swtimer",0,5,nil,nil,nil) ; view:insert(minlbl) ; view.minlbl = minlbl
		minlbl.text = "00"
		--
		local seplbl = gv:createText("swtimer",40,5,nil,nil,nil) ; view:insert(seplbl) ; view.seplbl2 = seplbl
        seplbl.text = "."
		--
		local seclbl = gv:createText("swtimer",80,5,nil,nil,nil) ; view:insert(seclbl) ; view.seclbl = seclbl
		seclbl.text = "00"
	view.x, view.y = gv.deviceCenterX, 3
	swtimer.view = view

	-- Update TIme
	function view:update(strvl)
		timer.allowIterationsWithinFrame = true
		local str = gv:swtimems( strvl )
		local splitstr = gv:split(str,":")
		self.hourlbl.text = ( tostring( splitstr[1] ) )
		self.seplbl1.text = (":")
		self.minlbl.text = ( tostring( splitstr[2] ) )
		self.seplbl2.text = (".")
		self.seclbl.text = ( tostring( splitstr[3] ) )
		timer.allowIterationsWithinFrame = false
	return true
	end

	local function updatetime(event)
		swtimer.view.time = event.count/60
	    local secval = string.format( "%.2f", tostring(swtimer.view.time) )      
	    swtimer.view:update( secval )
	    secval = nil
	return true
	end

	local function updatedowntime(event)
		swtimer.view.time = event.count/60
		if swtimer.view.downtime then
			swtimer.view.time = ( swtimer.view.downtime - ( event.count/60 ) )
		end
		if swtimer.view.time < 0 then
			swtimer.view:stop()
			swtimer.view.time = 0
			swtimer.view:update( 0 )
			swaudio:stopingamebg("ffgame-gameplay")
			swipeaShowOverlay("timeend","slideUp",{animate = true},false,true)
		else
		    local secval = string.format( "%.2f", tostring(swtimer.view.time) )      
		    swtimer.view:update( secval )
		    secval = nil
	    end
	return true
	end

	function view:start()
		print("<< -- GAME TIMER STARTED UP -->>")
		self:stop()
		self.gtimer = timer.performWithDelay(1,updatetime,0)
	return true
	end

	function view:revstart()
		print("<< -- GAME TIMER STARTED DOWN -->>")
		self:stop()
		self.gtimer = timer.performWithDelay(1,updatedowntime,0)
	return true
	end

	function view:show()
		self.isVisible = true
	return true
	end

	function view:hide()
		self.isVisible = false
	return true
	end

	function view:stop()
		print("<< -- GAME TIMER STOPPED -->>")
		if self.gtimer then
			timer.cancel(self.gtimer)
			self.gtimer = nil
		end
	return true
	end

 return view
end

return swtimer


[TOPIC: post.html]
#2

gamebit.labs

[GLOBAL: userInfoPane.html]
gamebit.labs
  • Contributor

  • 224 posts
  • Corona SDK

There seems to be an issue with "event.count" firing up timely in the browser. Updated my code to use "event.time" and my count up and down timer syncs perfectly with stopwatch.


  • sporkfin likes this


[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: html5, timer, browser