implemented atlas loading
This commit is contained in:
parent
daa2093e26
commit
64fc9d91a1
@ -9,28 +9,28 @@
|
|||||||
"tileSize":{
|
"tileSize":{
|
||||||
"x":16,
|
"x":16,
|
||||||
"y":16
|
"y":16
|
||||||
},
|
|
||||||
"tilesetGeneric":{
|
|
||||||
"baseTexture":"textures/sheets/sheet.png",
|
|
||||||
"tiles":[
|
|
||||||
"testTile1",
|
|
||||||
"testTile2",
|
|
||||||
"testTile3",
|
|
||||||
"testTile4",
|
|
||||||
"testTile5",
|
|
||||||
"testTile6",
|
|
||||||
"testTile7",
|
|
||||||
"testTile8",
|
|
||||||
"testTile9",
|
|
||||||
"testTile10",
|
|
||||||
"testTile11",
|
|
||||||
"testTile12",
|
|
||||||
"testTile13",
|
|
||||||
"testTile14",
|
|
||||||
"testTile15",
|
|
||||||
"testTile16"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tilesetGeneric":{
|
||||||
|
"baseTexture":"textures/sheets/sheet.png",
|
||||||
|
"tiles":[
|
||||||
|
"testTile1",
|
||||||
|
"testTile2",
|
||||||
|
"testTile3",
|
||||||
|
"testTile4",
|
||||||
|
"testTile5",
|
||||||
|
"testTile6",
|
||||||
|
"testTile7",
|
||||||
|
"testTile8",
|
||||||
|
"testTile9",
|
||||||
|
"testTile10",
|
||||||
|
"testTile11",
|
||||||
|
"testTile12",
|
||||||
|
"testTile13",
|
||||||
|
"testTile14",
|
||||||
|
"testTile15",
|
||||||
|
"testTile16"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,35 +2,21 @@
|
|||||||
"datascheme":"htex",
|
"datascheme":"htex",
|
||||||
"version":"1",
|
"version":"1",
|
||||||
"textureData":{
|
"textureData":{
|
||||||
"texName":"testsheet",
|
"texName":"testanimsheet",
|
||||||
"texType":"atlas",
|
"texType":"atlas",
|
||||||
"atlas":{
|
"atlas":{
|
||||||
"atlasType":"tilesetgeneric",
|
"atlasType":"tilesetanimated",
|
||||||
"tileSize":{
|
"tileSize":{
|
||||||
"x":16,
|
"x":16,
|
||||||
"y":16
|
"y":16
|
||||||
},
|
},
|
||||||
"tilesetGeneric":{
|
"tilesetAnimated":{
|
||||||
"baseTexture":"textures/sheets/sheet.png",
|
"baseTexture":"textures/sheets/sheet.png",
|
||||||
"tiles":[
|
"sequences":[
|
||||||
"testTile1",
|
{"name":"testsequence1","sequenceStart":0,"sequenceEnd":7},
|
||||||
"testTile2",
|
{"name":"testsequence2","sequenceStart":8,"sequenceEnd":15}
|
||||||
"testTile3",
|
]
|
||||||
"testTile4",
|
}
|
||||||
"testTile5",
|
|
||||||
"testTile6",
|
|
||||||
"testTile7",
|
|
||||||
"testTile8",
|
|
||||||
"testTile9",
|
|
||||||
"testTile10",
|
|
||||||
"testTile11",
|
|
||||||
"testTile12",
|
|
||||||
"testTile13",
|
|
||||||
"testTile14",
|
|
||||||
"testTile15",
|
|
||||||
"testTile16"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
hGameTest/res/textures/sprites/missing.png
Normal file
BIN
hGameTest/res/textures/sprites/missing.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 161 B |
@ -1,3 +1,4 @@
|
|||||||
|
import assets.tilesets.TilesetGeneric;
|
||||||
import openfl.display.Bitmap;
|
import openfl.display.Bitmap;
|
||||||
import openfl.display.Stage;
|
import openfl.display.Stage;
|
||||||
import openfl.display.Bitmap;
|
import openfl.display.Bitmap;
|
||||||
@ -5,9 +6,9 @@ import openfl.display.BitmapData;
|
|||||||
import openfl.display.Sprite;
|
import openfl.display.Sprite;
|
||||||
import openfl.events.Event;
|
import openfl.events.Event;
|
||||||
import openfl.Assets;
|
import openfl.Assets;
|
||||||
import assets.TextureData;
|
|
||||||
import assets.SpriteSheet;
|
|
||||||
import assets.Scanner;
|
import assets.Scanner;
|
||||||
|
import assets.HTex;
|
||||||
|
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
@ -23,14 +24,19 @@ class Game
|
|||||||
//player.graphics.lineStyle(2,0xFF0000);
|
//player.graphics.lineStyle(2,0xFF0000);
|
||||||
//player.graphics.drawRect(0,0,16,16);
|
//player.graphics.drawRect(0,0,16,16);
|
||||||
// var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png");
|
// var bitmapData:BitmapData = Assets.getBitmapData("textures/sprites/character.png");
|
||||||
var sheetData:BitmapData = Assets.getBitmapData("textures/sheets/sheet.png");
|
|
||||||
var sheet:SpriteSheet = new SpriteSheet(sheetData);
|
|
||||||
|
|
||||||
var playerBitmap:Bitmap = new Bitmap(sheet.sprites[15]);
|
|
||||||
playerBitmap.scaleX = playerBitmap.scaleY = 10;
|
|
||||||
player.addChild(playerBitmap);
|
|
||||||
//TextureData.parseConfig();
|
|
||||||
Scanner.scanTextureDir();
|
Scanner.scanTextureDir();
|
||||||
|
var sheetData:BitmapData = Assets.getBitmapData("textures/sheets/sheet.png");
|
||||||
|
for(tex in Scanner.textures){
|
||||||
|
HTex.createTextureObjectFromJSON(tex);
|
||||||
|
}
|
||||||
|
//var sheet:SpriteSheet = new SpriteSheet(sheetData);
|
||||||
|
|
||||||
|
var playerBitmap:Bitmap = new Bitmap(TilesetGeneric.tilesetGenericMap["testsheet"].tileMap["testTile5"]);
|
||||||
|
var someotherbitmap:Bitmap = new Bitmap(TilesetGeneric.tilesetGenericMap["testsheet"].tileMap["testTile3"]);
|
||||||
|
|
||||||
|
playerBitmap.scaleX = playerBitmap.scaleY = 10;
|
||||||
|
player.addChild(playerBitmap);
|
||||||
|
//TextureData.parseConfig();
|
||||||
//Sys.
|
//Sys.
|
||||||
}
|
}
|
||||||
public function onEnterFrame(e:Event):Void
|
public function onEnterFrame(e:Event):Void
|
||||||
|
|||||||
@ -1,26 +1,38 @@
|
|||||||
package assets;
|
package assets;
|
||||||
|
|
||||||
import openfl.display.BitmapData;
|
import openfl.display.BitmapData;
|
||||||
import assets.schema.HTexSchema.TexV1;
|
import openfl.Assets;
|
||||||
|
import assets.schema.HTexSchema;
|
||||||
|
import assets.tilesets.TilesetGeneric;
|
||||||
|
import assets.tilesets.TextureAtlas;
|
||||||
|
import haxe.Json;
|
||||||
|
|
||||||
class HTex{
|
class HTex{
|
||||||
public static var hTexArray:Array<HTex> = [];
|
public static var hTexArray:Array<HTex> = [];
|
||||||
public var bitmaps:Array<BitmapData>;
|
public var bitmaps:Array<BitmapData>;
|
||||||
public var name:String = "";
|
public var name:String = "";
|
||||||
public function new(_name:String){
|
public function new(_name:String){
|
||||||
name = _name;
|
// name = _name;
|
||||||
if(hTexArray[name] == null)
|
// if(hTexArray[name] == null)
|
||||||
hTexArray[name] = name;
|
// hTexArray[name] = name;
|
||||||
}
|
}
|
||||||
public static function createTextureObjectFromJSON(path:String){
|
public static function createTextureObjectFromJSON(path:String){
|
||||||
var DATA:TexV1;
|
var DATA:TexV1;
|
||||||
var loadedData:String = Assets.getText(path);
|
var loadedData:String = Assets.getText(path);
|
||||||
var jsondata = Json.parse(loadedData);
|
var jsondata = Json.parse(loadedData);
|
||||||
DATA = jsondata;
|
DATA = jsondata;
|
||||||
DATA = TexV1;
|
if(DATA.datascheme == "htex"){
|
||||||
if(DATA.dataScheme == "htex"){
|
|
||||||
if(DATA.version == 1){
|
if(DATA.version == 1){
|
||||||
var texdata:TextureDataV1 = Data.textureData;
|
var td:TextureDataV1 = DATA.textureData;
|
||||||
|
var width:Int = td.atlas.tileSize.x;
|
||||||
|
var height:Int = td.atlas.tileSize.y;
|
||||||
|
if(td.atlas.atlasType == "tilesetgeneric"){
|
||||||
|
var baseTexturePath:String = td.tilesetGeneric.baseTexture;
|
||||||
|
var tileNames:Array<String> = td.tilesetGeneric.tiles;
|
||||||
|
var atlas:TextureAtlas = new TextureAtlas(Assets.getBitmapData(baseTexturePath),width,height);
|
||||||
|
var tileSetGeneric = new TilesetGeneric(td.texName, atlas, tileNames);
|
||||||
|
trace(tileSetGeneric);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
package assets;
|
|
||||||
|
|
||||||
import openfl.Assets;
|
|
||||||
import haxe.Json;
|
|
||||||
|
|
||||||
typedef TexturesV1={
|
|
||||||
var dataScheme:String;
|
|
||||||
var version:Int;
|
|
||||||
var textureData:{
|
|
||||||
var spriteSheets:Array<{
|
|
||||||
var sheetNamekeke:String;
|
|
||||||
var path:String;
|
|
||||||
var sheetDataPath:String;
|
|
||||||
var explicitDimensions:Bool;
|
|
||||||
var tileDimensions:{
|
|
||||||
var width:Int;
|
|
||||||
var height:Int;
|
|
||||||
};
|
|
||||||
}>;
|
|
||||||
var sprites:Array<{
|
|
||||||
var spriteName:String;
|
|
||||||
var path:String;
|
|
||||||
}>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class TextureData{
|
|
||||||
public static var textures:Array<Any> = [];
|
|
||||||
public static function parseConfig(path:String = "data/textures.json"){
|
|
||||||
var DATA:TexturesV1;
|
|
||||||
var loadedData:String = Assets.getText(path);
|
|
||||||
var jsondata = Json.parse(loadedData);
|
|
||||||
DATA = jsondata;
|
|
||||||
//var test:String = File.getContent(test.txt);
|
|
||||||
trace(DATA);
|
|
||||||
/*typedef DataModal=
|
|
||||||
{
|
|
||||||
var ID:Int;
|
|
||||||
var NAME:String;
|
|
||||||
var TAGS:Array<String>;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
27
hGameTest/src/assets/files/TextureFile.hx
Normal file
27
hGameTest/src/assets/files/TextureFile.hx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package assets;
|
||||||
|
|
||||||
|
import openfl.display.BitmapData;
|
||||||
|
import openfl.Assets;
|
||||||
|
import haxe.Json;
|
||||||
|
import assets.tilesets.Tileset;
|
||||||
|
|
||||||
|
class TextureFile{
|
||||||
|
public static var pathMap:Map<String,TextureFile>;
|
||||||
|
public static function addUser(path:String, user:Dynamic):Void
|
||||||
|
{
|
||||||
|
if(pathMap[path] == null){
|
||||||
|
pathMap[path] = new TextureFile();
|
||||||
|
}
|
||||||
|
pathMap[path].users.push(user);
|
||||||
|
}
|
||||||
|
public static function removeUser():Void
|
||||||
|
{
|
||||||
|
if()
|
||||||
|
}
|
||||||
|
public var bitmapData:BitmapData = null;
|
||||||
|
public var users:Array<Dynamic>=[];
|
||||||
|
public var path:String;
|
||||||
|
private function new(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,7 +6,6 @@ typedef TileSetGenericV1={
|
|||||||
var baseTexture:String;
|
var baseTexture:String;
|
||||||
var tiles:Array<String>;
|
var tiles:Array<String>;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TileSetAnimatedV1={
|
typedef TileSetAnimatedV1={
|
||||||
var baseTexture:String;
|
var baseTexture:String;
|
||||||
var animations:Array<{
|
var animations:Array<{
|
||||||
@ -23,25 +22,14 @@ typedef TextureDataV1={
|
|||||||
var tileSize:{
|
var tileSize:{
|
||||||
var x:Int;
|
var x:Int;
|
||||||
var y:Int;
|
var y:Int;
|
||||||
},
|
};
|
||||||
var tileSetGeneric:TileSetGenericV1;
|
|
||||||
var tileSetAnimated:TileSetAnimatedV1;
|
|
||||||
}
|
}
|
||||||
var path:String;
|
var tilesetGeneric:TileSetGenericV1;
|
||||||
var sheetDataPath:String;
|
var tilesetAnimated:TileSetAnimatedV1;
|
||||||
var explicitDimensions:Bool;
|
|
||||||
var tileDimensions:{
|
|
||||||
var width:Int;
|
|
||||||
var height:Int;
|
|
||||||
};
|
|
||||||
var sprites:Array<{
|
|
||||||
var spriteName:String;
|
|
||||||
var path:String;
|
|
||||||
}>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef TexV1={
|
typedef TexV1={
|
||||||
var dataScheme:String;
|
var datascheme:String;
|
||||||
var version:Int;
|
var version:Int;
|
||||||
var textureData:TextureDataV1;
|
var textureData:TextureDataV1;
|
||||||
}
|
}
|
||||||
@ -4,7 +4,6 @@ import openfl.display.BitmapData;
|
|||||||
class Sequence{
|
class Sequence{
|
||||||
public var bitmaps:Array<BitmapData> = [];
|
public var bitmaps:Array<BitmapData> = [];
|
||||||
public var name:String = "";
|
public var name:String = "";
|
||||||
public var currentFrame = 0;
|
|
||||||
public function new(_name:String, _bitmaps:Array<BitmapData>){
|
public function new(_name:String, _bitmaps:Array<BitmapData>){
|
||||||
name = _name;
|
name = _name;
|
||||||
bitmaps = _bitmaps;
|
bitmaps = _bitmaps;
|
||||||
|
|||||||
@ -1,25 +1,24 @@
|
|||||||
package assets;
|
package assets.tilesets;
|
||||||
|
|
||||||
import openfl.geom.Point;
|
import openfl.geom.Point;
|
||||||
import openfl.geom.Rectangle;
|
import openfl.geom.Rectangle;
|
||||||
import openfl.display.BitmapData;
|
import openfl.display.BitmapData;
|
||||||
import openfl.display.Bitmap;
|
import openfl.display.Bitmap;
|
||||||
class SpriteSheet{
|
class TextureAtlas{
|
||||||
public static var spriteSheetArray:Array<SpriteSheet> = [];
|
public static var tileSetArray:Array<TextureAtlas> = [];
|
||||||
public var sprites:Array<BitmapData> = [];
|
public var sprites:Array<BitmapData> = [];
|
||||||
|
public var columns:Int;
|
||||||
|
public var rows:Int;
|
||||||
public function new(bmp:BitmapData = null, sprWidth:Int = 16, sprHeight:Int = 16){
|
public function new(bmp:BitmapData = null, sprWidth:Int = 16, sprHeight:Int = 16){
|
||||||
spriteSheetArray.push(this);
|
tileSetArray.push(this);
|
||||||
var columns:Int = cast((bmp.width / sprWidth),Int);
|
columns = cast((bmp.width / sprWidth),Int);
|
||||||
var rows:Int = cast((bmp.height / sprHeight),Int);
|
rows = cast((bmp.height / sprHeight),Int);
|
||||||
//trace("columns:"+columns);
|
|
||||||
//trace("rows"+rows);
|
|
||||||
for(i in 0...rows){
|
for(i in 0...rows){
|
||||||
for (j in 0...columns){
|
for (j in 0...columns){
|
||||||
var bmpd:BitmapData = new BitmapData(sprWidth, sprHeight,true,0x00000000);
|
var bmpd:BitmapData = new BitmapData(sprWidth, sprHeight,true,0x00000000);
|
||||||
var rect:Rectangle = new Rectangle(j*sprWidth,i*sprHeight,sprWidth,sprHeight);
|
var rect:Rectangle = new Rectangle(j*sprWidth,i*sprHeight,sprWidth,sprHeight);
|
||||||
bmpd.copyPixels(bmp, rect, new Point(0,0));
|
bmpd.copyPixels(bmp, rect, new Point(0,0));
|
||||||
sprites.push(bmpd);
|
sprites.push(bmpd);
|
||||||
//trace("i:"+i+",j:"+j);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
hGameTest/src/assets/tilesets/Tileset.hx
Normal file
13
hGameTest/src/assets/tilesets/Tileset.hx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package assets.tilesets;
|
||||||
|
|
||||||
|
|
||||||
|
class Tileset{
|
||||||
|
public static var tilesetMap:Map<String, Tileset> = [];
|
||||||
|
public var texName:String;
|
||||||
|
public var texAtlas:TextureAtlas;
|
||||||
|
public function new(name:String, atlas:TextureAtlas){
|
||||||
|
texName = name;
|
||||||
|
texAtlas = atlas;
|
||||||
|
tilesetMap[name] = this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,20 @@
|
|||||||
package assets.tilesets;
|
package assets.tilesets;
|
||||||
|
|
||||||
|
import openfl.display.BitmapData;
|
||||||
class TilesetGeneric {
|
import assets.tilesets.TextureAtlas;
|
||||||
|
|
||||||
|
|
||||||
|
class TilesetGeneric extends Tileset{
|
||||||
|
public var tileMap:Map<String, BitmapData> = [];
|
||||||
|
public function new(name:String, atlas:TextureAtlas ,tileNames:Array<String>){
|
||||||
|
super(name,atlas);
|
||||||
|
for(i in 0...texAtlas.sprites.length-1){
|
||||||
|
trace(i);
|
||||||
|
trace(tileNames[i]);
|
||||||
|
var sprites:Array<BitmapData> = texAtlas.sprites;
|
||||||
|
tileMap[tileNames[i]] = texAtlas.sprites[i];
|
||||||
|
}
|
||||||
|
trace(tileMap);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user