Closed hardcoremore closed 6 years ago
It is necessary in the sense that the API can't give you access to the internal Array/Vector, because it must not be modified.
However, I don't think I've ever used that property. You can always call:
private static var sTouches:Vector.<Touch> = new <Touch>[];
private function onTouch(event:TouchEvent):void
{
// most of the time, you're interested in the current display object:
event.getTouches(this, null, sTouches);
// but if you need all of them, call it like this:
event.getTouches(stage, null, sTouches);
}
Then you've got no more allocations.
Oh great. That is good to know. I think I saw somewhere in the tutorial something like this:
var allTouches:Vector.<Touch> = event.touches;
for(var i:int = 0, len:int = allTouches.length; i < len; i++)
{
touch = allTouches[i];
if(touch.target && touch.cancelled !== true)
{
this.processTouch(touch, event);
}
}
and I used it ever since. Ok I will refactor to what you have suggested and get back with results.
Thanks!
Oh yes, it's definitely better to do that via event.getTouches
! Glad I could help. :smile:
https://github.com/Gamua/Starling-Framework/blob/365ece4199385d2e197219a2fa57114b42cb818d/starling/src/starling/events/TouchEvent.as#L210
Is this concat() necessary. It creates over 13 000 Vectors.
Take a look at the screenshot: https://ibb.co/i77Dn7
And here is the Scout Profile: https://goo.gl/NYXced
This was tested on iPhone 6s.