Currently I am working on a Tower Defence game using a combination of Scripting for the data tracking and Event Sheets for the basic behaviours.
I have the Towers being placed on the Tilemap Grid reliably, and can determine when I select a Tower object on the Tap before doing the grid coords.
While I CAN go manually through families of objects I setup, like the on-screen Pause Button, is there an easy/simple way to determine if I HAVENT tapped anything on a layer? Or at least a way of getting all objects within a layer without having to iterate over the whole object set?
Please find below my current OnTap "event" code, and the circles of the towers that have placed after I "tap" a text item
OnTap = (pointerEvent) =>
{
if(this.gameOverHit) return;
let mouseXYAr = this.towerLayer.cssPxToLayer(pointerEvent.clientX, pointerEvent.clientY);
const towers = this.runtime.objects.Towers.getAllInstances();
const foundTower = towers.find(s => s.containsPoint(mouseXYAr[0], mouseXYAr[1]));
if(foundTower == null)
{
mouseXYAr = this.gridLayer.cssPxToLayer(pointerEvent.clientX, pointerEvent.clientY);
if(this.tilemap.containsPoint(mouseXYAr[0], mouseXYAr[1]))
{
const tileSizeX = this.tilemap.tileWidth;
const tileSizeY = this.tilemap.tileHeight;
const cellCoords = [Math.floor(mouseXYAr[0]/tileSizeX), Math.floor(mouseXYAr[1]/tileSizeY)]
const towerMapResult = this.TowerMap[cellCoords[0]][cellCoords[1]];
if(towerMapResult != true)
{
if(this.currentMoney >= 10)
{
this.UpdateMoney(-10);
this.runtime.objects.basicTower.createInstance(2, cellCoords[0]*tileSizeX + tileSizeX/2, cellCoords[1]*tileSizeY + tileSizeY/2, true, "");
this.TowerMap[cellCoords[0]][cellCoords[1]] = true;
}
}
}
}
}