FictionalAroma's Recent Forum Activity

  • So in the end I kinda bit the bullet and went for the obvious - iterate over the objects and do the checks for each WI unfortunately.

    For this current project each layout is the size of the viewport so cssPxToLayer shouldn't have any issues with parallax/floating UI, but ill add a "dictionary" for layers so I don't have to do the coordinate conversion for every object!

     let mouseXYAr = this.towerLayer.cssPxToLayer(pointerEvent.clientX, pointerEvent.clientY);
    
     // go through each family of objects to ignore
     // if we find we are clicking on litterally any, return out do nothing
     const familiesToIgnoreIfClick = ["UITextButtons", "UIButtons", "UIOverlays"];
     
     // do an any of families has any clicked items, if yes, bail method 
     if(familiesToIgnoreIfClick.some(family => 
     this.runtime.objects[family].getAllInstances().some(
     wi => 
     wi.layer.isSelfAndParentsVisible &&
     wi.layer.isSelfAndParentsInteractive &&
     wi.isVisible &&
     wi.containsPoint(mouseXYAr[0], mouseXYAr[1]))
     ))
     {
     // bail out if ANY
     return;
     }
    
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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;
     }
     }
     }
     }
     }
    
    
FictionalAroma's avatar

FictionalAroma

Member since 30 Jan, 2023

None one is following FictionalAroma yet!

Trophy Case

  • 1-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Regular Visitor Visited Construct.net 7 days in a row
  • RTFM Read the fabulous manual
  • Email Verified

Progress

5/44
How to earn trophies