Help With Lag In My MultiTouch Drawing App
Posted: 14 August 2013 10:19 AM   [ Ignore ]
Rank
Joined  2013-01-08
Total Posts:  15
New Member

I have been building a pretty complex MultiTouch drawing app, but when I test it on a touch screen I am getting some pretty bad lag for some reason. It would be great if someone could take a look at my multitouch code and let me know what I can change to optimize it!

Also, whenever I start touching on the monitor and draw, and then move back to a mouse the mouse no longer works to draw after I use the touch screen. Any help is greatly appreciated!

public function addListener() : void
        {
            
if(Multitouch.supportsTouchEvents)
            
{
                Multitouch
.inputMode                 =     MultitouchInputMode.TOUCH_POINT;
                
GraffitiSpray.gs.addEventListener(TouchEvent.TOUCH_BEGINonTouchBeginfalse0true);
                
GraffitiSpray.gs.addEventListener(TouchEvent.TOUCH_MOVEonTouchMovefalse0true);
                
GraffitiSpray.gs.addEventListener(TouchEvent.TOUCH_ENDonTouchEndfalse0true);
            
}
            
            GraffitiSpray
.gs.addEventListener(MouseEvent.MOUSE_MOVEonMouseMoveHandlerfalse0true);
            
GraffitiSpray.gs.addEventListener(MouseEvent.MOUSE_UPonMouseUpHandlerfalse0true);
            
GraffitiSpray.gs.addEventListener(MouseEvent.MOUSE_OVERonMoveOverHandlerfalse0true);
            
GraffitiSpray.gs.addEventListener(MouseEvent.RIGHT_CLICKonRightClickHandlerfalse0true);
            
GraffitiSpray.gs.addEventListener(MouseEvent.MOUSE_DOWNonMouseDownHandlerfalse0true);
            
            
update();
        
}
        
        
protected function onTouchBegin(event:TouchEvent) : void
        {

And then for each drawing utensil I have the following code:

protected function onTouchMove(event:TouchEvent) : void
        {
            
if(isdrawing)
            
{
                
if(sprite
                
{
                    
if(Globals.ActiveBrush == 0)
                    
{
                        sprite                             
=     Sprite(MovieClip(touchstack[event.touchPointID]).getChildAt(0));
                        
sprite.graphics.lineTo(event.stageXevent.stageY);
                    
}
                    
else if(Globals.ActiveBrush == 1)
                    
{
                        
for(var i:Number 08i++)
                        
{
                            sprite                         
=     Sprite(MovieClip(touchstack[event.touchPointID]).getChildAt(i));
                            
sprite.graphics.lineTo(event.stageXevent.stageY);
                        
}
                    }
                    
else if(Globals.ActiveBrush == 2)
                    
{
                        
for(var j:int 03j++)
                        
{
                            
if(== 0)
                            
{
                                xoffset                 
=     yoffset = -0.2;
                            
}
                            
if(== 1)
                            
{
                                xoffset                 
=     yoffset 0;
                            
}
                            
if(== 2)
                            
{
                                xoffset                 
=     yoffset 0.2;
                            
}
                            sprite                         
=     Sprite(MovieClip(touchstack[event.touchPointID]).getChildAt(i));
                            
sprite.graphics.lineTo(translateX(event.stageX), translateY(event.stageY));
                        
}
                    }
                    
else if(Globals.ActiveBrush == 3)
                    
{
                        
for(var k:int 03k++)
                        
{
                            
if(== 0)
                            
{
                                xoffset                 
=     0.2;
                                
yoffset                 =     -0.2;
                            
}
                            
if(== 1)
                            
{
                                xoffset                 
=     yoffset 0;
                            
}
                            
if(== 2)
                            
{
                                xoffset                 
=     -0.2;
                                
yoffset                 =     0.2;
                            
}
                            sprite                         
=     Sprite(MovieClip(touchstack[event.touchPointID]).getChildAt(i));
                            
sprite.graphics.lineTo(translateX(event.stageX), translateY(event.stageY));
                        
}
                    }
                    
else if(Globals.ActiveBrush == 5)
                    
{
                        id                                 
=     event.touchPointID;
                        
sprite                             =     Sprite(MovieClip(touchstack[event.touchPointID]).getChildAt(0));
                        
sprite.graphics.lineTo(event.stageXevent.stageY);
                        
                        
dripfactorinterval                 =     count == -setInterval(getDripPosition5) : dripfactorinterval;
                        
count                             =     0;
                    
}
                }
            }
        }

Thanks!

Profile
 
 
Posted: 14 August 2013 08:29 PM   [ Ignore ]   [ # 1 ]
Avatar
RankRank
Joined  2009-05-06
Total Posts:  158
Member

I’ve found that one of the biggest causes of lag is using the Win7 HID driver (or MT Vista) for CCV to native touch. If you are able to - and are using CCV - I would recommend changing your touch events to use a TUIO library such as TUIOAS3 (http://bubblebird.at/tuioflash/tuio-as3-library/) which gets touch data directly from CCV via TUIO UDP without the driver in the middle slowing things down. I have experienced huge gains this way, going from 2-3 touches with lots of lag to 10 touches with minimal lag.

Having said that, one thing you could try in your code is to change the if-else statements to a switch-case statement. This can improve performance when there are many cases to check but I think there would be minimal difference with just 5 cases.

switch (Globals.ActiveBrush)
{
    
case :
        
        break;
    case 
:
        
        break;
    case 
:
        
        break;
    case 
:
        
        break;
    case 
:
        
        break;
}

 Signature 

web: http://www.nemenvisual.com
blog: http://www.purplesquirrels.com.au

Profile
 
 
Posted: 14 August 2013 09:31 PM   [ Ignore ]   [ # 2 ]
Rank
Joined  2013-01-08
Total Posts:  15
New Member

That’s the strange thing, even when not using a HID driver (I.E. I used it on an actual MultiTouch screen, not an MT table). Do you have any other ideas on what it could be? Also, I tried implementing the TUIO but have been having major issues. Would you mind helping me out with that?

Thank you very much for your help!

Profile