-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameObjectPool.as
81 lines (75 loc) · 2.29 KB
/
GameObjectPool.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package
{
import flash.events.Event;
public class GameObjectPool
{
public var Objects:Array = new Array();
public var animation:Boolean = true;
private static var _instance:GameObjectPool = new GameObjectPool();
public static function get Instance():GameObjectPool//делаем синглетон
{
trace("getInstance");
return _instance;
}
public function Search(name:String):GameObject
{
var response:GameObject;
for each(var object:GameObject in Objects)
{
if(object.type == name)
{
response = object;
break;
}
}
return response;
}
public function GameObjectPool():void
{
trace("Constructor");
if(_instance)
throw new Error("Use Instance Field");
}
public function ApplyBitmapData():void
{
for each(var object:GameObject in Objects)
{
object.graphics.beginBitmapFill(GraphicsPool.Instance.SearchBitmap(object.type).bitmapData);
object.graphics.drawRect(0,0,GraphicsPool.Instance.SearchBitmap(object.type).width,GraphicsPool.Instance.SearchBitmap(object.type).height);
}
Game.Instance.addEventListener(Event.ENTER_FRAME,Game.Instance.Loop);
}
public function AlternateBitmapData():void
{
for each(var object:GameObject in Objects)
{
if (!object.isDead)
{
if(animation)
{
object.graphics.beginBitmapFill(GraphicsPool.Instance.SearchBitmap(object.type).bitmapData);
object.graphics.drawRect(0,0,GraphicsPool.Instance.SearchBitmap(object.type).width,GraphicsPool.Instance.SearchBitmap(object.type).height);
animation = false;
}
else
{
object.graphics.beginBitmapFill(GraphicsPool.Instance.SearchBitmap(object.type+"1").bitmapData);
object.graphics.drawRect(0,0,GraphicsPool.Instance.SearchBitmap(object.type+"1").width,GraphicsPool.Instance.SearchBitmap(object.type+"1").height);
animation = true;
}
}
else if(!object.isRemoved)
{
object.graphics.beginBitmapFill(GraphicsPool.Instance.SearchBitmap("aliendead").bitmapData);
object.graphics.drawRect(0,0,GraphicsPool.Instance.SearchBitmap("aliendead").width,GraphicsPool.Instance.SearchBitmap("aliendead").height);
object.isRemoved = true;
}
else
{
object.graphics.clear();
Game.Instance.removeChild(object);
}
}
}
}
}