开发者

Flash CS4 / AS3 symbol within symbols

I'm trying to create a multi-level dungeon adventure in Flash CS4. The layou开发者_如何学编程t 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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜