Well, they are only made once and that’s it… They are made in the gameworld…
Gameworld:
package game_handling
{
import assets.hp_globe.HpGlobe;
import assets.hp_globe.HpGlobe_HP;
import assets.stamina_bar.StaminaBarGraphic;
import assets.stamina_bar.StaminaGraphic;
import assets.xp_bar.XpBarGraphic;
import assets.xp_bar.XpGraphic;
import blocks.*;
import blocks.chests.Chest_Wooden;
import enemies.Goblin_Thief;
import events.Change_Room;
import flash.display.Bitmap;
import flash.geom.Point;
import hero.*;
import levels.level1.*;
import lit.Light;
import lit.Lighting;
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.graphics.Graphiclist;
import net.flashpunk.graphics.Image;
import net.flashpunk.graphics.Stamp;
import net.flashpunk.graphics.Tilemap;
import net.flashpunk.masks.Grid;
import net.flashpunk.World;
import talents.*;
public class GameWorld extends World
{
[Embed(source="../assets/circle_gradient2.png")]
public static const SPR_LIGHT_CIRCLE_GRADIENT:Class;
private var stats:HeroStats = new HeroStats();
private var xpbar:XpBarGraphic = new XpBarGraphic(470, 1040);
private var xpbar_xp:XpGraphic = new XpGraphic(470, 1040);
private var hpglobe:HpGlobe = new HpGlobe(30, 30);
private var hpglobe_hp:HpGlobe_HP = new HpGlobe_HP(30, 30);
private var staminabar:StaminaBarGraphic = new StaminaBarGraphic(250, 30);
private var staminabar_stamina:StaminaGraphic = new StaminaGraphic(250, 30);
private var gui:HUD = new HUD();
private var sounds:Sounds = new Sounds();
public var lighting:Lighting;
public var mouseLight:Light;
private var _map_Ground_Accessories_2:Tilemap;
private var _map_Ground_Accessories:Tilemap;
private var _map_Ground:Tilemap;
private var _map_BG_Accessories_2:Tilemap;
private var _map_BG_Accessories:Tilemap;
private var _map_BG:Tilemap;
public var collisionData:Grid;
public static var currentLevelIsScrollable:Boolean = false;
public static var currentLevel:int = 0;
private var _rawMapData:Class;
private var _scrollable:Boolean;
private var _tileset:Class;
public function GameWorld(map:Class, tileset:Class, isScrollable:Boolean)
{
_rawMapData = map
_tileset = tileset
_scrollable = isScrollable
}
override public function begin():void
{
super.begin();
//Hero stats
add(stats);
//Hp and xp graphics
add(hpglobe);
add(hpglobe_hp);
add(xpbar);
add(xpbar_xp);
add(staminabar);
add(staminabar_stamina);
//HUD
add(gui);
add(sounds);
loadLevel(_rawMapData, _tileset, _scrollable);
}
override public function update():void
{
super.update();
}
public function setNewMap(map:Class, tileset:Class, isScrollable:Boolean):void
{
_rawMapData = map;
loadLevel(_rawMapData, _tileset, _scrollable);
}
public function loadLevel(levelNumber:Class, tileset:Class, scrollable:Boolean):void
{
currentLevelIsScrollable = scrollable;
var tileSet:Class = tileset
var mapXML:XML = FP.getXML(levelNumber);
var mapWidth:uint = uint(mapXML.@width);
var mapHeight:uint = uint(mapXML.@height);
var tileX:uint = 0;
var tileY:uint = 0;
collisionData = new Grid(mapWidth * 128, mapHeight * 128, 128, 128);
_map_Ground_Accessories_2 = new Tilemap(tileSet, mapWidth * 128, mapHeight * 128, 128, 128);
_map_Ground_Accessories = new Tilemap(tileSet, mapWidth * 128, mapHeight * 128, 128, 128);
_map_Ground = new Tilemap(tileSet, mapWidth * 128, mapHeight * 128, 128, 128);
_map_BG_Accessories_2 = new Tilemap(tileSet, mapWidth * 128, mapHeight * 128, 128, 128);
_map_BG_Accessories = new Tilemap(tileSet, mapWidth * 128, mapHeight * 128, 128, 128);
_map_BG = new Tilemap(tileSet, mapWidth * 128, mapHeight * 128, 128, 128);
var amountOfTiles:int = 0;
for each (var layer:XML in mapXML.layer)
{
var XMLlayers:String = layer.attribute("name");
switch (XMLlayers)
{
case "Ground_Accessories_2":
tileX = 0;
tileY = 0;
for each (var tile:XML in layer.data.tile)
{
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
if (tile.@gid != 0)
{
_map_Ground_Accessories_2.setTile(tileX, tileY, uint(tile.@gid - 1));
}
tileX++;
}
break;
case "Ground_Accessories":
tileX = 0;
tileY = 0;
for each ( tile in layer.data.tile)
{
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
if (tile.@gid != 0)
{
_map_Ground_Accessories.setTile(tileX, tileY, uint(tile.@gid - 1));
}
tileX++;
}
break;
case "Ground":
tileX = 0;
tileY = 0;
for each (tile in layer.data.tile)
{
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
if (tile.@gid != 0)
{
collisionData.setTile(tileX, tileY, true);
}
if (tile.@gid != 0)
{
_map_Ground.setTile(tileX, tileY, uint(tile.@gid - 1));
}
tileX++;
}
break;
case "BG_Accessories_2":
tileX = 0;
tileY = 0;
for each (tile in layer.data.tile)
{
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
if (tile.@gid != 0)
{
_map_BG_Accessories_2.setTile(tileX, tileY, uint(tile.@gid - 1));
}
tileX++;
}
break;
case "BG_Accessories":
tileX = 0;
tileY = 0;
for each (tile in layer.data.tile)
{
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
if (tile.@gid != 0)
{
_map_BG_Accessories.setTile(tileX, tileY, uint(tile.@gid - 1));
}
tileX++;
}
break;
case "BG":
tileX = 0;
tileY = 0;
for each (tile in layer.data.tile)
{
if (tileX >= mapWidth)
{
tileX = 0;
tileY++;
}
if (tile.@gid != 0)
{
_map_BG.setTile(tileX, tileY, uint(tile.@gid - 1));
}
tileX++;
}
break;
}
}
trace(amountOfTiles)
for each (var objectgroup:XML in mapXML.objectgroup)
{
var groupname:String = objectgroup.attribute("name");
switch (groupname)
{
case "Spawn":
for each (var object:XML in objectgroup.object)
{
var spawnname:String = object.attribute("name");
switch (spawnname)
{
case "Hero":
FP.world.add(new Hero(new Point(int(object.@x * 8), int(object.@y * 8))));
break;
case "Goblin_Thief":
FP.world.add(new Goblin_Thief(new Point(int(object.@x * 8), int(object.@y * 8))));
break;
}
}
case "Chests":
for each (object in objectgroup.object)
{
var chestname:String = object.attribute("name");
switch (chestname)
{
case "Wooden":
FP.world.add(new Chest_Wooden(new Point(int(object.@x * 8), int(object.@y * 8))));
break;
}
}
case "Events":
for each (object in objectgroup.object)
{
var eventname:String = object.attribute("name");
switch (eventname)
{
case "Change_Room":
FP.world.add(new Change_Room(new Point(int(object.@x * 8), int(object.@y * 8))));
break;
}
}
}
}
//_map_BG.scrollX = 0.2;
//addGraphic(_map_Ground)
addGraphic(_map_BG, 1);
addGraphic(_map_BG_Accessories);
addGraphic(_map_BG_Accessories_2);
addGraphic(_map_Ground_Accessories, -2)
addGraphic(_map_Ground_Accessories_2, -3)
updateCollision();
}
public function updateCollision():void
{
var collision_:Collision = FP.world.getInstance("collision");
if (collision_ == null)
FP.world.add(new Collision(0, 0, _map_Ground, collisionData))
else
{
FP.world.remove(collision_)
trace("updating collision")
}
}
//End
}
}
The XML:
<map version="1.0" orientation="orthogonal" width="15" height="9" tilewidth="16" tileheight="16">
<tileset firstgid="1" name="Dungeon_1" tilewidth="16" tileheight="16">
<image source="../output/Dungeon_1.png" trans="ffffff" width="96" height="96"/>
</tileset>
<layer name="BG" width="15" height="9">
<data>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="10"/>
<tile gid="11"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="11"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="11"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="11"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="11"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="11"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="10"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
</data>
</layer>
<layer name="BG_Accessories" width="15" height="9">
<data>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="23"/>
<tile gid="24"/>
<tile gid="25"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="26"/>
<tile gid="27"/>
<tile gid="28"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="23"/>
<tile gid="24"/>
<tile gid="25"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="29"/>
<tile gid="30"/>
<tile gid="31"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="26"/>
<tile gid="27"/>
<tile gid="28"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="29"/>
<tile gid="30"/>
<tile gid="31"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
</data>
</layer>
<layer name="Ground" width="15" height="9">
<data>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="7"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="5"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="7"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="13"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="3"/>
<tile gid="6"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="7"/>
<tile gid="12"/>
<tile gid="13"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="1"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="13"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="3"/>
<tile gid="12"/>
<tile gid="12"/>
<tile gid="13"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="1"/>
<tile gid="3"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="3"/>
<tile gid="1"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="6"/>
<tile gid="16"/>
<tile gid="17"/>
<tile gid="17"/>
<tile gid="18"/>
<tile gid="17"/>
<tile gid="3"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="4"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="14"/>
<tile gid="15"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
<tile gid="5"/>
</data>
</layer>
<layer name="Ground_Accessories" width="15" height="9">
<data>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="8"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="21"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="22"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="9"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="20"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="2"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="8"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
<tile gid="0"/>
</data>
</layer>
<objectgroup name="Chests" width="15" height="9">
<object name="Wooden" x="160" y="80" width="16" height="16"/>
</objectgroup>
<objectgroup name="Spawn" width="15" height="9">
<object name="Hero" x="32" y="96" width="16" height="16"/>
</objectgroup>
<objectgroup name="Events" width="15" height="9">
<object name="Change_Room" x="192" y="64" width="16" height="16"/>
</objectgroup>
</map>
The tileset used for level 1 is 12kb, 768 x 768…
I’m sorry for including all of the code, but I figured that every line can be crucial to performance?