Closed krazyjakee closed 11 years ago
To load the world generally you would do something like:
game.loadWorld('island2');
game.world //this is now the world you just loaded
The asset cache will hold the original JSON parsed object downlaoded by the loader, which is keyed by the name you passed:
var obj = gf.assetCache['island2'];
//obj is now the original parsed JSON (not a Map Instance)
var map = new gf.TiledMap(obj);
but I recommend just using loadWorld
and then accessing game.world
. You can also get layers in the map by their name:
//assuming you have an Object Group named 'player' that has your player object in the map
game.loadWorld('island2');
var player = game.world.findLayer('player');
player.spawn();
You can set the custom property name
on an object in the TiledEditor to make it spawn a specific entity from the spritepool. You will also need the texture
property which should be the key for the texture it should pull from the assetCache (either the name of the resource, or the url if you didn't specify a name when you preloaded it). Something like:
function MyEntity() {
//stuff...
}
gf.inherits(MyEntity, gf.Sprite);
//add your sprite to the pool
game.spritepool.add('name', MyEntity); //name here must match what you put in the 'name' property of the object in Tiled
//assuming you have an Object Group named 'player' that has your player object in the map
//and that object has the name 'name', and some texture set as well
game.loadWorld('island2');
var player = game.world.findLayer('player');
player.spawn(); //will spawn an instance of MyEntity if you set it all up right
Ok cool, you recommended using the world object to access the map right?
So let's say I have my world object (game.world)
How do I get from that world object to be able to simply move the map. Like .pan(100,100).
Are you looking for:
game.world.pan(x, y);
Great. What was confusing me is that in google dev tools I can't see what is inherited by the world object so I presumed pan was not available. A lot of this is just going to end up being guess work unless there is something I'm missing or some better way to understand what is available.
I'm guessing the docs aren't helpful if I'm doing things this way?
Not going to be 100% accurate, but the generated YUIDocs are up at:
Added a high level class diagram. Please enable Wiki
@mgutz that's great man, thank you very much!
@mgutz Very nice, the wiki is already enabled
Closing this for now, please feel free to open another issue with any questions/bugs
So in the previous issue I assigned my map a name and threw it into the loader:
That's great but then it disappeared into some sort of Asset Cache. How do I get into this cache and start manipulating the map object?
Is the process the same for any object? How can I do something like:
Thanks.