Easy Way to Detect NOT tapping something

0 favourites
  • 4 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • 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;
     }
     }
     }
     }
     }
    
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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;
     }
    
  • Hmm, maybe I'm understanding something wrong but wouldn't this work? (Pseudocode)

    	if X tapped -> { doThing(X); return;}
    	if Y tapped -> { doThing(Y); return;}
    	if Z tapped -> { doThing(Z); return;}
    
    	// nothing was tapped
    	doThing(Bail);
    	return;
    

    So, if everything that can be tapped resolves to false, you're left with "nothing was tapped". I guess you're sort of doing the inverse, and instead check "was nothing tapped" first, then handle all the tappable objects. But I think my version would spare you having to iterate over all objects that cannot be tapped and instead only iterate over the objects that can be tapped.

  • Hmm, maybe I'm understanding something wrong but wouldn't this work? (Pseudocode)

    > 	if X tapped -> { doThing(X); return;}
    	if Y tapped -> { doThing(Y); return;}
    	if Z tapped -> { doThing(Z); return;}
    
    	// nothing was tapped
    	doThing(Bail);
    	return;
    

    So, if everything that can be tapped resolves to false, you're left with "nothing was tapped". I guess you're sort of doing the inverse, and instead check "was nothing tapped" first, then handle all the tappable objects. But I think my version would spare you having to iterate over all objects that cannot be tapped and instead only iterate over the objects that can be tapped.

    That is essentially what I am doing instead, where the DoThing is nothing.

    Pusedo Code of essentially what I have -

    for each family in familyList
    {
    if any object in family is tapped
    	{ StopProcessing(); return; }
    }
    

    The Real Issue however is that the objects I am trying to determine if I have tapped are objects that have their actions sorted in the event sheet. The main example is the Pause Button. I have On Touch on the event sheet to activate the Pause function, but then the Scripting side has no visibility of that.

    The "other problem" is that layers that are set to transparent will bubble the UI Pointer event down to each lower layer.

    So where my layers are (with notations for click events):

    1. UIOverlay
    2. <-- pause button OnTap Coords
    3. Enemy
    4. Towers
    5. <-- sub-popup menu
    6. Grid
    7. <-- still spawns new tower through OnTouch/TouchPointer check on tick

    While it would be nice to go Layout -> Layer -> Objects On Layer unfortunately that linkage isn't there right now

    What I have also seem to have found through sheer accident is that once you mark a layer as "not interactive", essentially it turns off the collisions for itself and ALL lower layers so that is there as a potential work around. This does solve the while clicking around on the Menu problem, but I still will need to check if we select any other objects while the main level is running.

    The last experiment I will end up trying is adding a script element to the event sheet to determine if the same PointerEvent object is passed around, or only copies of the original

    If Yes, then essentially I MIGHT be able to include an Ignore flag to the PointerEvent

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)