Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How can I speed up line drawing? — Gideros Forum

How can I speed up line drawing?

ondesicondesic Member
edited July 2012 in General questions
I am drawing a line where one end is fixed and the other end is where I am touching the screen. Though the code works, the line has a lag while I am moving my finger. while moving my finger on the screen, it seems to take a 1/3 of a second to catch up. Here is the code:
local theLine= Shape
 
function Main()
	theLine= DrawLine(10,10,application:getDeviceWidth()/2,10,5,1,0xffffff)
	stage:addChild(theLine)
end
 
function onTouchMove(event)
	theLine:clear()
             ChangeLine( theLine,10,10,event.touch.x,event.touch.y,5,1,0xffffff)
end
 
function DrawLine(x1, y1, x2, y2, width, alpha, rgbcolor)
	local line = Shape.new()
	line:setLineStyle(width, rgbcolor, alpha)
	line:beginPath()
	line:moveTo(x1,y1)
	line:lineTo(x2, y2)
	line:endPath() 
	return line
end
 
function ChangeLine(which, x1, y1, x2, y2, width, alpha, rgbcolor)
	if which == theLine then
		theLine:setLineStyle(width, rgbcolor, alpha)
		theLine:beginPath()
		theLine:moveTo(x1,y1)
		theLine:lineTo(x2, y2) 
		theLine:endPath() 
	end
end
 
Main()
stage:addEventListener(Event.TOUCHES_MOVE, onTouchMove)
application:setBackgroundColor(0x000000)
Any thoughts?

Dislikes: pmorsand

+1 -1 (+0 / -1 )Share on Facebook

Comments

  • Even at 60fps you'll get lag as the latency of the touchscreen is about 100ms, some guy at MS did some tests and you need latency in the order of 10ms for accurate tracking.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • Thanks techdojo. That's very interesting information.
    I don't think I would have thought twice about this, except before Gideros, I was using a different environment and had near 0 lag doing the same thing on the phone.
Sign In or Register to comment.