android - Is there a way to make a hitTest in AS3 faster? -
i have made game in as3 android, , when test on pc works great, when try on android, hittests slow game down bit, example have 1 level have collect 9 coins, , whenever characters collect it, game freezes bit, , code use is
if (coin1.hittestobject(hero)){ coin1.visible=false; gate.y-=10; }
that all, 2 tasks program execute on hittest, slows down game... game 600kb big, don't think it's other parts of code, doesn't have sounds or else, hittests in game basically...
you swap hittestobject
approach. calculate distance coins hero, , remove them, if close enough. such math should work faster:
var somedistance: number = 4; var dx: number = hero.x - coin.x; var dy: number = hero.y - coin.y; if(math.sqrt(dx*dx + dy*dy) <= somedistance){ //gotcha! hero "collided" coin }
Comments
Post a Comment