Plotting/Deleting a path to follow using "On Touch"

0 favourites
  • 11 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Please bear with me, this issue I'm having has a few facets to it. I'll try to be clear and brief as possible. Thanks in advance for your help and suggestions.

    I'm working on a "turn-based" style of mobile space shooter. Every wave is preceded by an opportunity for the player to tap in the "action area" (where the spaceship and enemies exist) and lay down up to five destination points. Upon activating the action for that wave, the spaceship will follow those points in the order they were created. During this pre-action phase, the player can tap any existing destination point already laid down to delete it. Any destination points that were created after the one being deleted will have their order values decreased - so destination point 4 will become the new 3 when destination point 3 is deleted.

    This is a screenshot of my current set up - and I've tried SEVERAL variations (including using a tilemap...but I couldn't work out getting the correct X/Y coordinates for Pathfinder to follow).

    The problem I have discovered is that the deletion portion of my script here acts immediately after the creation of the ShipCourse objects, even though I added the stipulation of ON TOUCH END. It shouldn't delete anything YET because the object hasn't even been created until AFTER the touch is finished. At least...that's the check-n-balance I'm trying to work out. I've also tried using the ELSE condition to differentiate between when a ShipCourse object is being created or deleted.

    I am quite certain there's a nuance in the way C2/3 reads conditions versus how I understand them. I'd be very grateful for some insight and help. Thanks again!

  • Nesting "On any touch end" inside "Is touching" event looks weird to me, I never do this and I'm not sure how this supposed to work.

    Also, "Is touching" event can be triggered multiple times even if you very briefly touch the screen. If you need to execute this code just once every time player touches the screen, you should use "On touched" or "On tap object".

    I would do this:

    One tap adds a point, second tap removes it.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you, The multiple "Is Touching" conditions are to make sure certain events don't take place - such as tapping an enemy, which is later going to be used as a different feature. I'll implement your suggestions and see how it works!

  • No, I meant the system calls "Is touching" event many times (~60 times a second) while the finger is touching the screen.

    As a result, your ShipCourse sprites could be created several instances at once in one point. (maybe not with your code, but still)

    To avoid this, you should use "On touched object" or "On tap object" event - these are executed only once.

    I recommend "On tap object". Tap is a gesture and it helps filtering out accidental touches.

  • So this is what I edited my event sheet to...just as you suggested along with the particulars for what I'm trying to do...

    The OrderID instance variable is pre-assigned to each of the ShipCourse objects.

    Each ShipCourse object has animation frames (speed 0) of all the ShipCourse images lower than itself, as well. So, if ShipCourse3 (one of the objects in the ShipCourse family object) has its OrderID value decreased by 1, it will then appear to be ShipCourse2, and so on until it is destroyed. Basically, each ShipCourse object simply updates its appearance when an instance object is deleted.

    The check on the OrderID value is just to make sure that ONLY the ShipCourse objects that were created after the one being deleted are updated in their appearance.

    All that said, I implemented your advice and it still will not work as it should.

  • Hi Rhindon

    I don't fully understand properly what you trying to do but one thing I notice in the event 3 where you compare this:

    ShipCourse.OrderID > PlayerShip.NodeGridCounter :

    Action: Subtract Self.OrderID From Self.OrderID

    Is it not that all the ShipCourse that meet the condition will become OrderID = 0 ?? so you set the animation Frame to 0

    I read it many times what you trying to accomplish but I still can't understand fully

    Maybe if you explain it just step by step will be much easier to understand and maybe we can find an easier solution


    1-On tab (battlefield) >>>>What you referring here anyway is the water or background or something like this?

    2-Is touching ShipCourse >>> I wanna this to happen

    3-I wanna this to happen and so on

    Just my two cents

  • Rhindon

    This what I understood

    On touched battlefield

    And is touching (ShipCourse) : then destroy it and add 1 NodeGridCounter & Update all remaining the

    (ShipCourse) frames

    Else is not touching (ShipCourse) And (NodeGridCounter < 5) = Create ShipCourse & add 1 to NodeGridCounter

    Is that correct?

  • tarek2 - Thank you for pointing that out to me. The action should have been Subtract 1 from Self.OrderID. I have now corrected that.

    The "Battlefield" is a space on the screen where all the action takes place. I don't want the player tapping just anywhere and the destination markers (the ShipCourse objects) appearing where they shouldn't. The player can tap elsewhere on the screen, such as selecting a weapon type, as well. So the goal is to designate where the following actions will take place.

    Here's how it should go...

  • WOOPS! The edge of the picture cut off the details of what I'm trying to do.

    tarek2 - Thank you for your capx. That's pretty much what I'm trying to do, yes.

  • Rhindon

    I see what you mean now

    Cool glad you fixed

    Another thing if is just one frame animation you could do everything through one object and if you need to apply some special action to one of them only you can Ad an Instance Variable example : "Type" then on each one just add like ShipCourse1, ShipCourse2, ShipCourse3 etc.......then you can pick up any ship through that variable

    Capx: I put the Variable here but I didn't use it is just to show you


    My problem was in the variable I was using in order to identify WHICH ShipCourse objects to update. I was telling it to identify all objects above the variable that counted which ShipCourse to create NEXT and NOT from the value of the object that was deleted! So, if I had created up to four objects, the variable I had been using would have been 4. So if I deleted, say, the first object, the value was still 4 (or rather 3 after calculations), so it wasn't counting all the way back to the first object which was the deleted one.

    I created a new variable that stored the value of the deleted ShipCourse object and told it to update all objects AFTER that value (the one that was deleted). Thank you, guys, very much for your help all the same! I'm very grateful for your time.

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