View Full Version : hitTest: 12 / 24bit maximum
tarwin
January 16th, 2008, 08:44 PM
Hi,
I'm currently working on a platform game that makes large use of hitTestPoint (AS3). On levels that I was making enemies that were too far off screen to start with seemed to just fall through the world before I got to them, but for levels my work-mate was making all was fine.
A quick look (just moving characters closer and further away from the player manually) gave me a limit of around 3500px off the screen. I then guessed that the levels that were working had the objects (ground) that was being hitTest against bitmapCached. I was correct, in my friends they were. So I did a little experiment.
AS2
---------------------------
mBox._x = -15000000;
onEnterFrame = ef;
function ef(){
trace(mBox._x+":"+mBox.hitTest(mBox._x+1, 100, true));
mBox._x-=10000;
}
AS3
----------------------------
mBox.x = -3000;
addEventListener(Event.ENTER_FRAME, ef);
function ef(e:Event){
trace(mBox.x,mBox.hitTestPoint(mBox.x+1, 100, true));
mBox.x-=1;
}
I did this with and without bitmap caching on a box I drew on the stage. Interestingly the results I came up with were (almost) as follows.
With bitmap caching I could push the box off screen up to 16.7 million pixels. This is approx 2^24. After this it became erratic then totally disappeared from hitTests.
Without bitmap caching though I could only push the box 4096 (2^12) pixels off screen before I totally lost it.
I'm guessing this is something to do with vectors being able to be sub-pixel, but not sure. Hope this helps someone as it really left us stumped for quite a while.
hatu
January 17th, 2008, 04:06 AM
Why do you apply physics to enemies that are 16 million pixels away?
Spawn them when you're 1000 pixels away or something. Or start the AI and physics then.
tarwin
January 17th, 2008, 04:23 AM
It was more the 4096px I was worried about. We had large levels and were doing all our physics at once. I know it doesn't sound like it was needed, and you can fix it quickly by doing some kind of AABB check to see how far away it is, but this had problems. For example, if you have a row of "enemies" running back and forth, they will go out of sync if you only move them when they are a certain distance from the screen (as you run towards them one will run while others don't etc).
hatu
January 17th, 2008, 04:31 AM
Maybe try dividing the levels into areas and run the 2-3 areas around the character. When you enter a new area you would start all the enemies at the same time.
You can't really have huge maps and lots of enemies without some kind of" streaming principle" behind it. It's gonna be a problem sooner or later anyway.
tarwin
January 17th, 2008, 07:25 PM
Yeah thanks hatu. We're working on that kind of idea at the moment. I guess to start with it was just annoying to set all this stuff up (I'm lazy).
We are implementing this kind of thing anyway now.
It's interesting how fast AS3 is when you use some optimized code. We're doing AABB checks to see how far away (I know not real distance) objects are from the player every frame and it takes almost no time at all from the CPU! Ah, I love AS3 :)
The main reason for this post was documentation of that fact that Flash has these hard limits because I had not found it listed anywhere else.
ArmoredSandwich
January 18th, 2008, 06:45 AM
Maybe the list that you are looking for is something like this?
http://www.kirupa.com/forum/showthread.php?t=16877
And how is AS3 much faster? Does it has a better editor than the flas8 one.
The problem with me is that often I make typos etc, and those take ages to find. It's so much harder to code something in flash 8 than Microsoft Visual studio as in the studio it automagically displays properties, methods etc of a class when you're typing for it. You can even input your own documentary for your classes.
Obviously it would be awesome to have something like that for flash 8. My question is, is it something like that with cs3? Or whatever you use (heard Sirisian talking about a plug in or something once).
Btw, to get back on topic. I think what you are looking for might be quadtrees. Look it up in google or something.
Sorry for the half offtopic post ;)
hatu
January 18th, 2008, 06:58 AM
There's good lazy and bad lazy though.
Good is when you write good code that makes things easier later on.
Bad is when you write bad code to save a few minutes of thinking now but which will take hours of your time later on.
I've given up on so many games because I realized I'd need to rewrite everything that I just don't go there anymore :P
robotz
January 20th, 2008, 07:46 AM
The problem with me is that often I make typos etc, and those take ages to find. It's so much harder to code something in flash 8 than Microsoft Visual studio as in the studio it automagically displays properties, methods etc of a class when you're typing for it. You can even input your own documentary for your classes.
Obviously it would be awesome to have something like that for flash 8. My question is, is it something like that with cs3? Or whatever you use (heard Sirisian talking about a plug in or something once).
You want to use FlashDevelop - it's free, it provides everything you listed above, and it absolutely rocks! I could not code in AS3 without it (well perhaps I could use eclipse, but until I need that level of project management FlashDevelop will work great for me).
hatu
January 20th, 2008, 08:14 AM
You want to use FlashDevelop - it's free, it provides everything you listed above, and it absolutely rocks! I could not code in AS3 without it (well perhaps I could use eclipse, but until I need that level of project management FlashDevelop will work great for me).
I think the Flash plugin for eclipse costs quite alot too. Flashdevelop is great and you can use it for AS1, 2 and 3
tarwin
January 20th, 2008, 09:13 AM
ArmoredSandwitch: Thanks, just checking out quadtrees now. They seem quite interesting, but I think probably not worth setting up at the moment, the hitTest built into Flash is doing well enough so far.
The image of a quadtree really reminds me of H264 encoding. Oh I think it might be (http://www.ece.ucdavis.edu/PCS2004/pdf/ID112.PDF).
hatu: Don't give up - being lazy only teaches you how much you need to not be next time - you get smarter and being lazy anyway.
Oh, and Flashdevelop is amazingly good. I find Eclipse can be heavy going at times, but Flashdevelop is lean. Eclipse does have better refactoring though I think.
Give it a go with AS3 and you'll fall in love with Flash all over again!
ArmoredSandwich
January 20th, 2008, 01:09 PM
flashDevelop seems like it is exactly what I need! Thank you so much, this will speed up my project so much.
Can't believe I didn't asked that before. Thanks guys :)
therobot
March 22nd, 2008, 03:25 PM
this had problems. For example, if you have a row of "enemies" running back and forth, they will go out of sync if you only move them when they are a certain distance from the screen (as you run towards them one will run while others don't etc).
Someone else spammed this thread and dug it up, but I do have something to add in relation to the quote above.
If you have formations of enemies you want to keep in sync, you can still wait to activate them until the hero gets close enough, just store the enemies you want in formation in an array. When an enemy is activated, just check if their formationArray.length > 0, and if so, activate everyone else in it. Easy, and probably more efficient than activating every enemy in an area (depending on how big the areas are).
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.