how do you get the data from a specific layer of the weltmeister map I've seen people use getTile but only on the collision layer i would like to pull the data stored in the level.js file if that's possible.
for example if I wanted to create swimming events when the player were on a water tile without the water being a collision. Is there a way of doing this?
1 decade ago
by Joncom
/*
* Returns true if any tiles within 'tiles' are found at x, y
* on the map layer named 'layer'.
*
* @param x int Position on x-axis in tiles.
* @param y int Position on y-axis in tiles.
* @param tiles array Tiles to check for.
* @param layer string Name of layer containing tile.
* @return bool true if tile is queried type, else false.
*/
isSpecialTile: function(x, y, tiles, layer)
{
// Search all map layers.
for (var i = 0; i < this.backgroundMaps.length; i++) {
// Find the layer with the correct name.
if (this.backgroundMaps[i].name == layer) {
// Try all tiles for a match.
for (var j = 0; j < tiles.length; j++)
{
if (tiles[j] == this.backgroundMaps[i]['data'][y][x])
return true; // Found match!
}
break; // No need to search further.
}
}
return false; // No match found.
}
If you&
039;re like me, you'll have several different tiles which can represent water, but should all be considered swimmable. So if the tile you're checking at #x, y
matches any of the tiles in
tiles
the function returns true. Otherwise false.
That looks really useful to me I'll try it. I'm actually planning on having more types than just water such as trap hexes, falls, sand that slows the players speed., etc. too so I might want to return the data to a switch-case
Follow up question.
What function can I use to get a frame from a png of a given tile size
I expect something takes the (file location,size-x.size-y) and returns an object but I don't see anything under images. Should I just use the gettile function?
I feel like this is essentially the same type of code and its returning an error
I've tinkered with it and when I put in hard data for x and y it works and when I put in
x and y it works outside of my for loop... also hard data for the .length doesn't work so I can't find my error.
Cannot read property '0' of undefined it seems to think
0 is a property and not a value
tiles = ig.game.getMapByName('hexes');
for (y=0;y<tiles.data.length;y++){
for (x=0;x<tiles.data[y].length;x++){
switch (tiles.data[x][y]){
case 13:
settings = {name:13}
ig.game.spawnEntity(EntityIsomap,x*HEX_SIZE,y*HEX_SIZE,settings);
break;
}
}
}
1 decade ago
by Joncom
Quote from ShawnSwander
What function can I use to get a frame from a png of a given tile size
I expect something takes the (file location,size-x.size-y) and returns an object but I don't see anything under images. Should I just use the gettile function?
Something like this?
Source
// Load an image
var img = new ig.Image( 'player.png' );
// Draw the whole image
img.draw( x, y );
// Draw one 'tile' of the image
// (tile 3, with a tilesize of 16x16 pixels)
img.drawTile( x, y, 3, 16 );
joncom
yeah I thought of that and I ran into two problems and one is kind of big
the small problem is I don't see my img.drawTile when I run the function which I would normally tweak and figure out what is wrong.
Bigger problem is I wana blow up 55 pixel images to 385 for this feature (and I'm okay with the blur or pixelation) but the way impact knows where my tiles are on the png is by the size so I'd have to resize it after the fact.
I made an entity solution but I can't make it bigger increasing the size doesn't appear to do anything. I could make it scaleable in weltmeister but that doesn't help me here either.
This is how I spawned it... my syntax isn't right on the settings but it still spawns the default hex but its only 55pixels and the default setting is 385
if( ig.input.state('rightclick')){
tiles = ig.game.getMapByName('hexes');
tilex = parseInt(ig.input.mouse.x / HEX_SIZE);
tiley = parseInt(ig.input.mouse.y / HEX_SIZE);
settings = "{currentAnim: {anims:"+tiles.data[tilex][tiley]+";}}";
ig.game.spawnEntity(EntityHexzoom, this.pos.x-165,this.pos.y-165,settings);
var hexzoom = ig.game.getEntitiesByType( EntityHexzoom );
hexzoom.anims = tiles.data[tilex][tiley]
}
Page 1 of 1
« first
« previous
next ›
last »