-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcameraShake.as
55 lines (48 loc) · 1.12 KB
/
cameraShake.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
package
{
import net.flashpunk.*;
public class cameraShake extends Entity
{
public static var cameraJitterCounter:int = 0;
private static var saveCameraX:Number;
private static var saveCameraY:Number;
public function cameraShake()
{
}
public static function activateCameraJitter(jitterCount:int):void
{
if (cameraJitterCounter == 0) { // if already shaking do nothing
cameraJitterCounter = jitterCount;
saveCameraX = FP.camera.x; // save camera coords
saveCameraY = FP.camera.y;
}
}
override public function update():void
{
if (cameraJitterCounter > 0)
{
cameraJitterCounter--;
if (cameraJitterCounter == 0)
{
FP.camera.x = saveCameraX;
FP.camera.y = saveCameraY;
}
else
{
var cameraXOffset:Number = Math.random() * 5;
if (Math.random() < 0.5)
{
cameraXOffset = -cameraXOffset;
}
var cameraYOffset:Number = Math.random() * 5;
if (Math.random() < 0.5)
{
cameraYOffset = -cameraYOffset;
}
FP.camera.x = saveCameraX + cameraXOffset;
FP.camera.y = saveCameraY + cameraYOffset;
}
}
}
}
}