-
Notifications
You must be signed in to change notification settings - Fork 0
/
StarlingTiledMapGameState.as
60 lines (43 loc) · 1.82 KB
/
StarlingTiledMapGameState.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
package tiledmap.starling {
import citrus.core.starling.StarlingState;
import citrus.objects.platformer.box2d.Hero;
import citrus.objects.platformer.box2d.Platform;
import citrus.physics.box2d.Box2D;
import citrus.utils.objectmakers.ObjectMakerStarling;
import citrus.view.starlingview.StarlingArt;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
import flash.display.Bitmap;
import flash.geom.Point;
import flash.geom.Rectangle;
/**
* @author Aymeric
*/
public class StarlingTiledMapGameState extends StarlingState {
[Embed(source="/../embed/tiledmap/map-atlas.tmx", mimeType="application/octet-stream")]
private const _Map:Class;
[Embed(source="/../embed/tiledmap/Genetica-tiles-atlas.xml", mimeType="application/octet-stream")]
private const _MapAtlasConfig:Class;
[Embed(source="/../embed/tiledmap/Genetica-tiles-atlas.png")]
private const _MapAtlasPng:Class;
public function StarlingTiledMapGameState() {
super();
// Useful for not forgetting to import object from the Level Editor
var objects:Array = [Hero, Platform];
}
override public function initialize():void {
super.initialize();
var box2D:Box2D = new Box2D("box2D");
// box2D.visible = true;
add(box2D);
var bitmap:Bitmap = new _MapAtlasPng();
var texture:Texture = Texture.fromBitmap(bitmap);
var xml:XML = XML(new _MapAtlasConfig());
var sTextureAtlas:TextureAtlas = new TextureAtlas(texture, xml);
ObjectMakerStarling.FromTiledMap(XML(new _Map()), sTextureAtlas);
var hero:Hero = getObjectByName("hero") as Hero;
view.camera.setUp(hero, new Point(stage.stageWidth / 2, 240), new Rectangle(0, 0, 1280, 640), new Point(.25, .05));
(view.getArt(getObjectByName("foreground")) as StarlingArt).alpha = 0.3;
}
}
}