-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGameState.hx
76 lines (61 loc) · 1.9 KB
/
GameState.hx
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
package;
import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import openfl.filters.BlurFilter;
import world.World;
/**
* Extends basic FlxState with additional functionality
*
* @author Joe Williamson
*/
class GameState extends FlxState {
public var world:World;
public var uiGroup:FlxSpriteGroup;
public var uiCamera:FlxCamera;
public var worldCamera:FlxCamera;
public var worldZoom(default, set):Float;
public var baseZoom:Float;
public var zoomTween:FlxTween;
override public function create():Void {
super.create();
// Cameras
worldCamera = FlxG.camera;
uiCamera = new FlxCamera(Std.int(FlxG.camera.x), Std.int(FlxG.camera.y),
FlxG.camera.width, FlxG.camera.height, FlxG.camera.zoom);
uiCamera.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(uiCamera);
FlxCamera.defaultCameras = [worldCamera];
baseZoom = worldCamera.zoom;
worldZoom = 1;
// Groups
uiGroup = new FlxSpriteGroup();
uiGroup.cameras = [uiCamera];
add(uiGroup);
var blur:BlurFilter = new BlurFilter();
worldCamera.flashSprite.filters.push(blur);
worldCamera.flashSprite.filters = worldCamera.flashSprite.filters;
}
public function zoomTo(zoom:Float, duration:Float = 1, ?ease:Float->Float):FlxTween {
if (ease == null) ease = FlxEase.quadInOut;
if (zoomTween != null) {
zoomTween.cancel();
}
zoomTween = FlxTween.tween(this, { worldZoom: zoom }, duration, { type: FlxTween.ONESHOT, ease: ease } );
return zoomTween;
}
private function set_worldZoom(worldZoom:Float):Float {
// Set world and camera zoom
worldCamera.zoom = baseZoom * worldZoom;
return this.worldZoom = worldZoom;
}
//TODO autotweening
//TODO camera targetting
//TODO sound fading
}