0

I'm trying to create a multi-level dungeon adventure in Flash CS4. The layout is an instance created of a symbol called Level, within the symbol are multiple wall subsymbols (wall), instances of Wall. There is a collision routine to stop the player walking through the walls, called from Wall.As. Level is drawn about the centre point (0,0). When I create an instance on the stage of Level (level), the collision tester is using the xy coordinates for the walls drawn about 0,0, not the "real" xy where it's appearing on the stage. So what I need to know, is how to "update" the xy for each wall subsymbol with the live stage information, overriding the XYs drawn in the parent. It has to be updated unfortunately (I can't keep it static), as the levels are big so have to scroll.

Thanks for your advice.

3 Answers3

1

With all due respect forget your approach, you're reinventing the wheel for nothing and probably to end up getting worse performance. What you need is pixel-perfect collision detection and probably including basic physics so already we're talking a huge amount of work. If you want to build levels in a design way for a game, use this, it'll blow your mind how awesome/easy/cool this is:

http://www.gotoandlearn.com/play.php?id=135

  • actually doing pixel perfect collision using bitmapData and points is faster, it's not noticable on most pcs but if you port flash apps to mobile you see the difference. – Saad Apr 06 '11 at 21:05
  • I'm not quite sure I get your comment, does my answer imply the pixel perfect bitmap based collision is slower? If you're just making a statement I agree, the bitmapdata class is very very fast in flash. –  Apr 07 '11 at 01:30
0

Its always a guess when trying to answer questions like this, as there are a lot of unknowns. That being said, in programming, there are always more than a few ways to solve a problem. Examine your collision detection routine - if you worked with hitTestPoint, and the point that was being tested (mouseX,Y or your main actor) with localToGlobal, you likely wouldn't need to test for the x,y variables of your collision objects. Read up on those two subjects and this question might be rendered moot.

At any rate, you could update relative coordinates in your Wall.as instance by leveraging globlaToLocal:

public function get curLoc():Point 
{
    return globalToLocal(new Point(this.x, this.y));
}

and retrieve them from your parent class as a point you can then test against:

trace(_wall.curLoc);

Hope that helps

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
Bosworth99
  • 4,206
  • 5
  • 37
  • 52
  • does localToGlobal work regardless of how "deep" the sprite is (the sprite obj is create maybe under another sprite object which is on stage? – Saad Apr 06 '11 at 21:10
  • @Saad I believe it does but localToGlobal and globalToLocal are finicky methods that have to be employed in a specific manner. http://www.emanueleferonato.com/2010/06/22/understanding-as3-localtoglobal-method/. –  Apr 07 '11 at 01:33
0

I suppose you could accomplish what you're trying to do by manipulating the transform property of the wall symbols, but honestly I would concur with Ascension Systems and just abandon your collision testing routine for something different.

You may not need to go all out with a physics engine for your game, in which case just use hitTestObject to do the collision detection.

jhocking
  • 5,527
  • 1
  • 24
  • 38