开发者

Continuous movieclips with collision-detection in AS3?

I'm starting to understand ActionScript and getting better with it. However, I'm building a platform game with an unlimited length. What would be the best way to create the "block" the player is jumping on?

I'm not really familiar with anything else than array. Are there any other ways? Of course collision detection for these movieclips is needed (nicest would be to do it without a giant loop through an array, etc. on every frame). There's probably some开发者_StackOverflow社区thing like 5 block on the screen at the same time.

Thanks, Martti Laine


You can test a collision with the function hitTestObject or hitTestPoint

However keeping a list of every block in the game in an array and looping through it and checking for a collision on every frame does not sound like it would scale well.

If its really only 5 elements that might be OK to loop through an array but I would not check it every frame, only check once every time the player or block moves. If at frame X their is no collision and nothing has moved since frame X then there must still be no collision.

Not sure if it would work, but maybe keep all the blocks in a container and check to see if the container is colliding with the player. However this might not work as it might trigger if the player is within the containers bounding box and not actually touching one if it's children.


If you mean "unlimited length" as "seamless world", you can't store all the blocks in an Array (since you don't have unlimited memory). You will need to research in procedural creation of levels, and store few screens on memory only.

Once you have that, you have to limit the collision detection with only the visible collidable elements, using the method that John described in his post.

Also, try using Vector class if you can target to FP 10, because it's faster (if you use only one type of object in an Array).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜