implemented atlas loading
This commit is contained in:
		
							parent
							
								
									570816c0b5
								
							
						
					
					
						commit
						56d4651228
					
				| @ -9,28 +9,28 @@ | ||||
|             "tileSize":{ | ||||
|                 "x":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", | ||||
|     "version":"1", | ||||
|     "textureData":{ | ||||
|         "texName":"testsheet", | ||||
|         "texName":"testanimsheet", | ||||
|         "texType":"atlas", | ||||
|         "atlas":{ | ||||
|             "atlasType":"tilesetgeneric", | ||||
|             "atlasType":"tilesetanimated", | ||||
|             "tileSize":{ | ||||
|                 "x":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" | ||||
|                 ] | ||||
|             } | ||||
|         "tilesetAnimated":{ | ||||
|             "baseTexture":"textures/sheets/sheet.png", | ||||
|             "sequences":[ | ||||
|                 {"name":"testsequence1","sequenceStart":0,"sequenceEnd":7}, | ||||
|                 {"name":"testsequence2","sequenceStart":8,"sequenceEnd":15} | ||||
|             ] | ||||
|         } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											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.Stage; | ||||
| import openfl.display.Bitmap; | ||||
| @ -5,9 +6,9 @@ import openfl.display.BitmapData; | ||||
| import openfl.display.Sprite; | ||||
| import openfl.events.Event; | ||||
| import openfl.Assets; | ||||
| import assets.TextureData; | ||||
| import assets.SpriteSheet; | ||||
| import assets.Scanner; | ||||
| import assets.HTex; | ||||
| 
 | ||||
| 
 | ||||
| class Game | ||||
| { | ||||
| @ -23,14 +24,19 @@ class Game | ||||
| 		//player.graphics.lineStyle(2,0xFF0000); | ||||
|         //player.graphics.drawRect(0,0,16,16); | ||||
|         // 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(); | ||||
|         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. | ||||
| 	} | ||||
| 	public function onEnterFrame(e:Event):Void | ||||
|  | ||||
| @ -1,26 +1,38 @@ | ||||
| package assets; | ||||
| 
 | ||||
| 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{ | ||||
|     public static var hTexArray:Array<HTex> = []; | ||||
|     public var bitmaps:Array<BitmapData>; | ||||
|     public var name:String = ""; | ||||
|     public function new(_name:String){ | ||||
|         name = _name; | ||||
|         if(hTexArray[name] == null) | ||||
|             hTexArray[name] = name; | ||||
|         // name = _name; | ||||
|         // if(hTexArray[name] == null) | ||||
|         //     hTexArray[name] = name; | ||||
|     } | ||||
|     public static function createTextureObjectFromJSON(path:String){ | ||||
|         var DATA:TexV1; | ||||
|         var loadedData:String = Assets.getText(path); | ||||
|         var jsondata = Json.parse(loadedData); | ||||
|         DATA = jsondata; | ||||
|         DATA = TexV1; | ||||
|         if(DATA.dataScheme == "htex"){ | ||||
|         if(DATA.datascheme == "htex"){ | ||||
|             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 tiles:Array<String>; | ||||
| } | ||||
| 
 | ||||
| typedef TileSetAnimatedV1={ | ||||
|     var baseTexture:String; | ||||
|     var animations:Array<{ | ||||
| @ -23,25 +22,14 @@ typedef TextureDataV1={ | ||||
|         var tileSize:{ | ||||
|             var x:Int; | ||||
|             var y:Int; | ||||
|         }, | ||||
|         var tileSetGeneric:TileSetGenericV1; | ||||
|         var tileSetAnimated:TileSetAnimatedV1; | ||||
|         }; | ||||
|     } | ||||
|     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; | ||||
|     }>; | ||||
|     var tilesetGeneric:TileSetGenericV1; | ||||
|     var tilesetAnimated:TileSetAnimatedV1; | ||||
| } | ||||
| 
 | ||||
| typedef TexV1={ | ||||
|     var dataScheme:String; | ||||
|     var datascheme:String; | ||||
|     var version:Int; | ||||
|     var textureData:TextureDataV1; | ||||
| } | ||||
| @ -4,7 +4,6 @@ import openfl.display.BitmapData; | ||||
| class Sequence{ | ||||
|     public var bitmaps:Array<BitmapData> = []; | ||||
|     public var name:String = ""; | ||||
|     public var currentFrame = 0; | ||||
|     public function new(_name:String, _bitmaps:Array<BitmapData>){ | ||||
|         name = _name; | ||||
|         bitmaps = _bitmaps; | ||||
|  | ||||
| @ -1,25 +1,24 @@ | ||||
| package assets; | ||||
| package assets.tilesets; | ||||
| 
 | ||||
| import openfl.geom.Point; | ||||
| import openfl.geom.Rectangle; | ||||
| import openfl.display.BitmapData; | ||||
| import openfl.display.Bitmap; | ||||
| class SpriteSheet{ | ||||
|     public static var spriteSheetArray:Array<SpriteSheet> = []; | ||||
| class TextureAtlas{ | ||||
|     public static var tileSetArray:Array<TextureAtlas> = []; | ||||
|     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){ | ||||
|         spriteSheetArray.push(this); | ||||
|         var columns:Int = cast((bmp.width / sprWidth),Int); | ||||
|         var rows:Int = cast((bmp.height / sprHeight),Int); | ||||
|         //trace("columns:"+columns); | ||||
|         //trace("rows"+rows); | ||||
|         tileSetArray.push(this); | ||||
|         columns = cast((bmp.width / sprWidth),Int); | ||||
|         rows = cast((bmp.height / sprHeight),Int); | ||||
|         for(i in 0...rows){ | ||||
|             for (j in 0...columns){ | ||||
|                 var bmpd:BitmapData = new BitmapData(sprWidth, sprHeight,true,0x00000000); | ||||
|                 var rect:Rectangle = new Rectangle(j*sprWidth,i*sprHeight,sprWidth,sprHeight); | ||||
|                 bmpd.copyPixels(bmp, rect, new Point(0,0)); | ||||
|                 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; | ||||
| 
 | ||||
| 
 | ||||
| class TilesetGeneric { | ||||
| import openfl.display.BitmapData; | ||||
| 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