Hi Helmut,
Not sure how much use you'll get out of this, but I did a talk a while back
on this subject, and the conference notes can be found here:
http://londonmmug.org/downloads/presentations/20040916-London-MMUG-Alias-Cummins-Flash-games.zip
What you have here is an algorithm with exponential complexity - that is, it
gets exponentially more resource intensive with each element added. Ideally,
you would want an algorithm which would increase CPU load linearly (that is,
adding a little each time you add a new element, rather than multiplying by
itself).
There are a number of techniques which you can use to reduce the workload on
your code, however, it's hard to know what you're trying to do from looking
at your code. Can you describe in a little more detail how you want this to
work? Are you checking for collisions between any object and any other
object? Where does the mouse position come into it? can you drag items? etc.
Let me know,
Alias
On 31/08/06, Helmut Granda <[EMAIL PROTECTED]> wrote:
Hello,
I have 10 items on screen and only 2 of them have to match. so there is no
problem saying itemA.hiTest(itemB). But now I have to know if
itemA.hitTest(itemB)
+ itemC.
The only way i got it to work is by having itemC onEnterFrame check if the
mouse is on top of it. The issue here is that I have 8 items that are
constantly runing the onEnterFrame and I was wondering if I could have
some
advice on how to avoid that.
Here is some of the code:
//basic code:
for (i:Number = 1; i < 10; i++)
{
......code here
this["food" + i + "_single"].onRelease = this["food" + i +
"_single"].onReleaseOutside = function ()
{
//If Success
if (object.hitTest(receiver)){
var id:Number = this._name.charAt(4);
this._parent["food"+id].gotoAndStop("highlight");
makeItDissapear(itemNumFinal, this._width,this._height,
_root._ymouse);
}
else
{
returnToOrigin (itemNumFinal, _root._xmouse, _root._ymouse);
}
}
};
//Extra Items
for (var j:Number = 1 ; j < 8 ; j++)
{
var idName2:String = "ram" + j;
this.attachMovie ( idName2, idName2, this.getNextHighestDepth() + j)
this["ram" + j]._x = ramInfo[j][0];
this["ram" + j]._y = ramInfo[j][1];
this["ram" + j].onEnterFrame = function() {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
trace("hit" + this._name);
}
}
};
It all works puurfectly but I was trying to find a way to optimize and not
have 8 items checking for hitText constantly.
TIA
--
...helmut
<http://helmutgranda.com>
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com