0

我已经完成了一个角色四处走动,收集东西并射击敌人的迷宫游戏。游戏完全是动态制作的。我现在想添加一个战争迷雾,角色只能在一定的圆半径内看到他周围的东西。我使用精灵/电影剪辑创建了图像和背景图像。

我最初的想法是在整个地图上创建 5*5 的黑色方块,并让它们都运行一个事件监听器来查看它们是否被击中,如果它们被击中,则将 alpha 更改为 0。但我认为它可能会因为太多的活动活动而使游戏陷入困境。有一个更好的方法吗?

谢谢。

4

1 回答 1

2

As I understand you need to create a fog of war on a minimap, so that hero only sees enemies, etc. around a predefined radius and can also see terrain if he has visited that part of the map. Something like this:

enter image description here

Where yellow paw is hero and red dots are enemies. Darker parts of the map have not been visited yet.

You can achieve this effect by using 2 masks, 1 for masking revealed part of the terrain and another one for masking the highlighted part of the terrain and enemies or other objects. So your layer structure should be something like this:

enter image description here

After setting up your layers, you can simply call the

beginFill(0xFF0000); // any color will do
drawCircle(mHero.x, mHero.y, radius);
endFill();

methods on the graphics object of darkened terrain mask (lower one). mHero is the instance name for the hero symbol on the minimap.

That's for the revealing part, for the highlight of the hero's position on the minimap you'll need to do the same for the highlighted terrain mask, but with the addition of clear() method at each draw call, so that old circles don't get saved. You'll have something like this for the highlighted terrain map graphics object:

clear();
beginFill(0xFF0000); // any color will do
drawCircle(mHero.x, mHero.y, radius);
endFill();
于 2013-11-04T15:01:30.330 回答