Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Patrick_Ascher

Hey there,
i have a new problem to solve. As you maybe know i am developing a little RPG game to get better in impact.

so now i have an enemy and one player. so i have a little problem with the layers because, if i am in front of the enemy my z-Index should be higher than the z-Index of the enemy and when i am behind ... this should change. (see 3rd picture)

So my first idea is to check the possions of the two entities (get height/2 of each other) and if some one is higher on the map the Z-Index is lesser. But what would be the best way to check, that i would have no preformance problems, becouse if i will check this in the player update section... this will be checkt 60 times per sec.

Good idea? or any better?
edit:
ah... some coffe.... i think the better/right solution would be, that i am checking the MAP height and the entity position... the lower the entity ... the higher the Z-Index?

My 2nd Problem is with the map. Here i have the same Problem.
Some is there a better solution than making 2 or more MAP layers with the right index?

/><br />
<br />
Thanks,<br />
Patrick			</div>
		</div>
			<div class=

1 decade ago by Patrick_Ascher

so i solved it that way with the entities yet

main.js -> update
//calculate Z-Index
this.entities.sort(sortByPosY);
for ( var i = 0; i < this.entities.length; i++) {
	this.entities[i].zIndex = i;
}

____

function sortByPosY(a, b) {
	var x = a.pos.y;
	var y = b.pos.y;
	return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}

but no idea how to solve it with the map

1 decade ago by dominic

For entities, you can use the new .autoSort and .sortBy properties:
MyGame = ig.Game.extend({
	autoSort: true,
	sortBy: ig.Game.SORT.POS_Y,
	...
});

For the map you could put all the overlapping tiles on a separate foreground layer. E.g. the tree tops and the upper half of the cross would be on a foreground layer in front of the entities.

1 decade ago by Patrick_Ascher

Hey dominic.

thanks for your answer. i will solve the map problem with a front and background layer.

But now to the SORT Function:

i already tried the autoSort and sortBy function. But that wasn´t working for me!
Maybe there is a bug?

i added this to my GAME:
MyGame = ig.Game.extend({
    autoSort: true,
    sortBy: ig.Game.SORT.POS_Y,
    ...
});

but nothing happens.

so i checked the game.js and looked if that gets fired...

	sortEntities: function() {
		this.entities.sort( this.sortBy );
	},

and yeah i got a full console.log :) ... so my next check was to replace the "this.sortBy" with the real function "function( a, b ){ return a.pos.y - b.pos.y; }" and that was working...

so there must be a problem with the sortBy?

Is that working for you???

regards,
Patrick

1 decade ago by dominic

Haha, damn. Another thing I didn&039;t think through completely. The #.sortBy is overwritten with the default ig.Game.SORT.Z_INDEX when the instance of your Game class is created.

Set the .sortBy in your Game&039;s #init() instead:
init: function() {
	this.sortBy = ig.Game.SORT.POS_Y;
}

Edit: or fix line 36 in lib/impact/game.js (I also updated it in the git repo):
this.sortBy = this.sortBy || ig.Game.SORT.Z_INDEX;
Page 1 of 1
« first « previous next › last »