marvster Posted May 14, 2014 Share Posted May 14, 2014 Like the line of sight demo on game mechanicexplorer (http://gamemechanicexplorer.com/#raycasting-1), I'd like use ray casting for enemy detection and movement (chasing), but on a big tilemap, with a specific layer holding the collision information for certain tiles. My questions are:- How can I get this ray cast demo work with tilemapLayer? I looked up the docs, but could figure it out.- How can I assure perfomance, as the whole map would consist easily 100-200 objects in general which need to be ray casted, even just a few are in a relevant range where line of sight detection makes sense? Link to comment Share on other sites More sharing options...
kass Posted May 14, 2014 Share Posted May 14, 2014 theres actually a official tilemap raycast example Link to comment Share on other sites More sharing options...
marvster Posted May 14, 2014 Author Share Posted May 14, 2014 Thanks alot kass, that was exactly what I wanted. Unfortunately my fear come true, as it seems, that all objects will be checked, even those not shown on the screen: I've tried to use the visible property of the sprite, but this seems not to be functional.this.enemyGroup.forEachExists(function (enemy) { this.game.physics.arcade.collide(this.player, enemy); var ray = new Phaser.Line(enemy.x, enemy.y, this.player.x, this.player.y); var tileHits = this.map.layer3.getRayCastTiles(ray, 4, true, false); if (tileHits.length > 0 && enemy.visible) { enemy.tint = 0xffffff; enemy.seePlayer = false; } else { enemy.tint = 0xffaaaa; enemy.seePlayer = true; } }, this);Any Idea? Link to comment Share on other sites More sharing options...
marvster Posted May 15, 2014 Author Share Posted May 15, 2014 Found a solution, even it seems not to work on every Browser:this.enemyGroup.forEach(function (enemy) { if (enemy.inCamera) { this.game.physics.arcade.collide(this.player, enemy); var ray = new Phaser.Line(enemy.x, enemy.y, this.player.x, this.player.y); var tileHits = this.map.layer3.getRayCastTiles(ray, 4, true, false); if (tileHits.length > 0 && enemy.inCamera) { enemy.tint = 0xffffff; enemy.seePlayer = false; } else { enemy.tint = 0xffaaaa; enemy.seePlayer = true; } } }, this);With a tilemap 1440x1440 and 100 objects, the frame rate was on Chrome between 50-60fps, in Firefox under 20fps (which broke collision detection) and in IE constant 60fps. It seems that Firefox will handle some stuff in a different way. Link to comment Share on other sites More sharing options...
Recommended Posts