carterza Posted September 17, 2014 Share Posted September 17, 2014 I'm trying to create a tilemap at runtime and I need to generate some of my maps tilesets at runtime as well. The game I'm making takes place in outer space, so I am generating starfields with using canvas and a BitmapData object. I want to do something similar to - map = game.add.tilemap(); // Add a Tileset image to the map map.addTilesetImage('ground_1x1'); // Creates a new blank layer and sets the map dimensions. // In this case the map is 40x30 tiles in size and the tiles are 32x32 pixels in size. layer1 = map.create('level1', 40, 30, 32, 32); layer1.scrollFactorX = 0.5; layer1.scrollFactorY = 0.5; // Resize the world layer1.resizeWorld();But I don't have an image stored in the cache, so I can't do : map.addTilesetImage('ground_1x1')... Normally I would use the loader to load my images, but since they're being created at runtime as BitmapData objects, I need to somehow get an image into the cache using the BitmapData object I've built. Any idea how to do this? Link to comment Share on other sites More sharing options...
lewster32 Posted September 18, 2014 Share Posted September 18, 2014 BitmapData objects can be added to the cache with a key - the game.add.bitmapData method you would typically use has this configurable in its parameters. Once generated these should be accessible in exactly the same way you'd access a loaded image. Link to comment Share on other sites More sharing options...
carterza Posted September 18, 2014 Author Share Posted September 18, 2014 Hey Lewster, thanks for the reply . I knew about the GameObjectFactory's bitmapData method, and I also know I could add one to the cache with Cache's addBitmapData method as well, but here's the screwed up part - Tilemap's addTilesetImage method only looks for images in the cache. The reason I'm using a BitmapData object in the first place, is because I need to create a randomized starfield. Maybe I'll just not add the starfield to the tilemap - I don't plan on having any sprites interact with the starfield. It doesn't really benefit from being included as a layer in the tilemap. Maybe I'll just add it directly to the stage and then add the tilemap on top of it. Link to comment Share on other sites More sharing options...
lewster32 Posted September 18, 2014 Share Posted September 18, 2014 Hmm, looking at the code it seems you're right. It should work but it's specifically looking for an image in the case of that method. To be honest I'd do the starfield as a TileSprite in the background, it'll be faster (the way TileMaps are drawn is not as efficient as the TileSprite scrolling routine) but this is probably something that should still be addressed. You may want to mention it as an issue on Github as it looks like it should be an easy fix. carterza 1 Link to comment Share on other sites More sharing options...
carterza Posted September 18, 2014 Author Share Posted September 18, 2014 Hmm, looking at the code it seems you're right. It should work but it's specifically looking for an image in the case of that method. To be honest I'd do the starfield as a TileSprite in the background, it'll be faster (the way TileMaps are drawn is not as efficient as the TileSprite scrolling routine) but this is probably something that should still be addressed. You may want to mention it as an issue on Github as it looks like it should be an easy fix.Good call on the tilesprite, I will post an issue on github as well. Thanks Lewster. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts