How do I block objects around another object from tap?

0 favourites
  • 13 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • The player taps a tile and either enemy, loot, or nothing spawns. What i want to happen is that if an enemy spawns then the tiles surrounding the enemy would change to a different object, which i can do fine, but then would not be able to be tapped until the enemy is defeated.

    I imagine that once i switch the tile out with another object that there is no touch command for that would take care of the player not being able to tap the tiles around the enemy but how do i set it up with the events to basically say if enemy spawns then surrounding tiles within 1 tile distance of enemy in all directions are untapable? or in all directions switch to this object?

    Lol i hope that what i am saying is making sense.

  • Hi rbailey83

    something like this??

    You didn't specify which types of tiles (Tilemaps, sprites tiles, etc..) so I just did it with Sprite Tiles, I hope it helps

    https://www.dropbox.com/s/al7t5tl7cvx1yv9/Tiles%20Spawn%20Objects.capx?dl=0

  • tarek2 yep that's exactly what i was trying to do thank you so much, So it's the detector that gets called in at enemy spawn, and whatever tiles the detector is overlapping it locks out is that right? How do you do the functions? I haven't seen that ability or is that from a plugin?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • tarek2 yep that's exactly what i was trying to do thank you so much, So it's the detector that gets called in at enemy spawn, and whatever tiles the detector is overlapping it locks out is that right? How do you do the functions? I haven't seen that ability or is that from a plugin?

    rbailey83 No problem man glad it was helphul

    Yeah that's right the Detector is the one checking for the neighbor's tiles of the enemy tile when is spawned but only checks overlap if the enemy was spawned also if you notice I exclude the enemy Tile on the overlap Checking , I used the function because is a Trigger so it checks the overlap once and also the Function are really good because you can pass the UID of the objects so you can do more extra staff to that particular object later on by just picking that UID

    You should definitely learn how to use the Functions if you can as has many benefits, they are very easy to learn and once you learned you will see is not much complicated and very useful

    The Function is an official plugin from c2, you can add the Function Plugin by going to the Right side panel and right click on the folder that says "Object Types" then choose insert new objects and then choose "Function"

    You can read more about it here

    https://www.scirra.com/manual/149/function

    I must be really tired when I did this yesterday as after wake up today and look it at it again a saw a few errors like the "trigger once" in one of the function so we don't need that in a function as the Function is already a trigger once so yeah haha I don't wanna show you bad habits I corrected that and another thing that we don't need is to create and destroy the detector that was unnecessary from my part so I update the Capx much cleaner

    https://www.dropbox.com/s/1lwpxn8k4pdgaie/Tiles%20Spawn%20Objects3.capx?dl=0

  • Yeah that's right the Detector is the one checking for the neighbor's tiles of the enemy tile when is spawn but only checks overlap if the enemy was spawn, I used the function because is a Trigger so it checks the overlap once and also the Function are really good because you can pass the UID of the objects so you can do more extra staff to that particular object later on by just picking that UID

    You should definitely learn how to use the Functions if you can as has many benefits, they are very easy to learn and once you learned you will see is not much complicated and very useful

    The Function is an official plugin from c2, you can add the Function Plugin by going to the Right side panel and right click on the folder that says "Object Types" then choose insert new objects and then choose "Function"

    You can read more about it here

    https://www.scirra.com/manual/149/function

    tarek2 Awesome thanks again! I have an understanding of functions from my baseline knowledge of programming language and how useful they can be. The function option is not listed for me though when i right click object types and choose insert new objects. it's up to date and a personal license

  • nevermind, i created a new project and looked from that and the function is showing, just wasn't showing for me when i tried looking for it in the example project you sent me

  • nevermind, i created a new project and looked from that and the function is showing, just wasn't showing for me when i tried looking for it in the example project you sent me

    Haa it may be that you had it already added to your project because once you added to your project you will not find it anymore on ad new objects because is already there and ready to use:

    This is the how is working on this new capx:

    Everything starts if you touch a tile

    On touched Tile:

    And the tile is not active meaning is untouched yet >> then choose random animation

    Then if the chosen animation is equal to "Enemy" then we call for the overlap check on the neighborhood

    Else: if is not the "Enemy animation" then we don't check overlaps just set the tile to active meaning that has been touched already you cant touch it anymore, and set the "Animated" to true this is to avoid any more animation change on this tile as will happen the scenario that will check for overlaps in different tiles and their neighbours and this one will be chosen again so by checking the "Animated to true" will be skipped

    If the Enemy has been chosen:

    Then The Function "CheckOberlaps" will check and do:

    -First, we filter to do the check to the none "Active Tiles"

    -One more filter don't check for the enemy tile which is = to Function.Param(0)

    -Then we proceed with the condition to check for the overlap

    Action: All the tiles overlapping and that meet the above Conditions >>set them to Active true

    Nex event on the Function:

    Pick the Enemy tile who called the Function = Function.Param(0)

    Action: set him to (Active & to Animated) true to avoid any further checking or animation change on him

    Last event on the Function:

    Now we pick all the ones that where Overlapping and the ones that haven't been animated yet = meaning still untouched

    Action: Then change animation & random choose Frames

    Action: set them all of them to animated = you cant touch them anymore

  • tarek2 Great! thanks for the extra breakdown of the event sheet, helps to simplify it a bit more. Was understanding most of what was going on, took me a minute to catch on to the family part lol.

    This has been great and thanks so much for not only being informative and helpful but even making the example project for me! Much appreciated!

  • tarek2 Hope you don't mind another question. I don't need the full solution I just want to know if I am barking up the right tree or if I need to switch my solution method.

    So I have setup the function and animations and all that jazz, When the enemy appears the player needs to be able to tap and interact with it and I could not get it to allow me to do that as an animation so I had that family tile spawn a new object with the enemy and then set the family tile animation to empty so that it wouldn't duplicate the enemy with the animation enemy.

    I then setup for the tap fight, and on enemy killed destroyed the enemy. In order to get the tiles to turn back to the default (tappable) tiles i set the instance variables back, both active and animated, to false after enemy destroy, and set the family tile animation back to default. I also tried just calling the function again after enemy destroyed. But that then also puts the tile back up on the one where the enemy had appeared and player defeated instead of staying empty.

    Here's an image of the code and link in case image doesn't show, Just want to know if I am heading in the right direction with destroying the object and resetting the animation no need to give the solution, i usually figure stuff out by trial and error i just don't want to spend hours on it if I am not even going in the right direction.

    I highlighted the area for on enemy death i didn't run it with both enemy death events i just did one at a time but included both for easier screenshot, but included full code in case you needed to see what i've done.

  • rbailey83

    Your Welcome mate I'm glad it was helpful

    And about the Last question about the Enemy fight:

    I think everyone has different ways of doing things so you will find that to do one particular thing you will able to do it in many different ways and you just choose the one that you feel comfortable with and that you find it easier to understand just in case you need to come back to it to update and make changes the only exception to this is the end result "Performance" so however, you choose to do it always look which one is the best performance that's one rule that you cant break I guess

    For what I see on the pictures:

    -One thing that I quickly see is that on the Event (20) >>>you don't reference to which tile is because you have only the Enemy_Ork in the picklist and you didn't pick the tile there so it will not work as intended, if you wanna do it that way you need to pick the right tile with the ork then that action knows to which tile needs to apply the action

    -On event 21 the same you don't pick the tile beforehand so all the action that you apply there you apply them to all the tiles in the game as is an unreferenced object

    -Event 20 and 21 have the same "Condition" >>>EnemyOrk.Health is = to 0 or less to something, you could just move the actions from event 21 to event 20 is the same thing you don't need extra checking the same thing

    ======================================================

    Now this is how would have done it, will be easier if we simplify

    We have all the code running from if only you click the tile and the tile is "not Active"

    so the easiest thing will be to make the logic to the inverse for the "Enemy Fight"

    Example:

    On clicked Tile

    Is (not active)

    we have done all the code for that

    Else (The Tile Is Active)

    And is the Enemy = Then Action: Call for the Enemy Fight

    Capx: https://www.dropbox.com/s/2v0ypg746c6n3pf/Tiles%20Spawn%20Objects4.capx?dl=0

    For what I understand if you Fight the Enemy and you destroy it the tile of the Enemy has to be inactive again to be able to interact with it again and I guess all the neighbor's tiles that the enemy looked before has to become inactive swell to be able to interact with them well if I'm not mistaking

  • tarek2 I apologize for not responding sooner, I haven't been feeling well the last few days. The events 20 and 21 I didn't actually have them in at the same time when I was testing, I just put them in for the screen shot to show the two ways that I had tried to do the < 0 health event is all.

    Ok i think I get what you mean, I created a new event for the fight that was outside the event where the tile that called the detection and spawned the enemy, so it is no longer dealing with the reference point for the tile id that actually spawned the object.

    I feel like an idiot, that is so obvious now after looking at the example project you posted. And thank you for that by the way. If i could recommend you for some kind of forum award for being helpful I would definitely be doing that.

  • rbailey83 No problem man I hope you feel better

    [quote:k5guynxz]The events 20 and 21 I didn't actually have them in at the same time when I was testing, I just put them in for the screen shot to show the two ways that I had tried to do the < 0 health event is all.

    see what you mean now sorry I didn't get what you meant at that time

    [quote:k5guynxz]I feel like an idiot, that is so obvious now after looking at the example project you posted

    you shouldn't feel like that is normal and is gonna happen very often, sometimes you don't see it at the first glance but you see it on the second or third etc..... especially in the beginning, to be honest I still do a lot of crazy things either for (tiredness, bored, Brain collapse, no enough Oxygen on the brain, etc...) that's why I make sure to review my events many times and especially on a different days because on a different day fresh it may you can see something that you didn't see before.

    [quote:k5guynxz]If i could recommend you for some kind of forum award for being helpful I would definitely be doing that.

    Hahaa Thank you very much sir, Even that the Award Tittle is far way bigger than the actual job it was done, That has to be one of the Coolest forms of Gratitude and appreciation that I see around, Is a pleasure to help colleagues like you

    ==========================================

    You see Talking about Review on different days today looking at the capx again I Spot a bug:

    When you fight with the Enemy and it happens the scenario that all the Eight Tiles neighbors surrounding the Enemy Are Inactive the Even 15 it wouldn't Run because all the Tiles are inactive included the Enemy Tile therefor the Detector will stay on the screen

    Example if this is the scenario and if you defeat the Enemy

    https://www.dropbox.com/s/luq7dkb2m7jvhfo/SpawnTileBug.png?dl=0

    One way To Fix that you can change to this:

    https://www.dropbox.com/s/ms3aqn0oosdnrtl/SpawnTileBugUpdate.png?dl=0

  • tarek2 I hadn't even noticed that, I had just quickly taken a look and ran the project to see the outcome, hadn't tried implementing it or studying it yet so you beat me to that. I did update it in the sample project that you gave me. Thanks for that!

    Def a good thing to take a break for a while and when come back to the project just quickly check things over again with a fresh mind.

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