How do I destroy a specific sprite copied several times?

0 favourites
  • 5 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi everyone!

    My proyect: drive.google.com/file/d/16pG8zAHyMygVKRaAqMUk1orSKVscGKqf/view

    First of all, sorry for my bad English! Its has been a while since I last wrote something on English!

    I’m a 24 years old teacher that is trying Construct for the first time. My objective is to make some games with my 12-16 years old students, and I have started making a TD game. Even though I haven’t study informatics or programming, I found Construct quite simple and I have mostly finished my game. However, I’m having a problem with one sprite:

    As you can see, there is a sprite named “Build”. That’s the base where the Towers are build and it helps me getting the coordinates. However, once a tower is built, I want to delete that sprite. I have looked a lot of tutorials about UID, IID, Variables, etc. but I haven’t figured out how could I make it. The problem is that I have copied that sprite several times and if I choose “destroy” all of them are destroyed. Can someone help me? Thanks!

    I’m also getting problems to switch between layouts. I have a “menu” layout and when the button gets clicked, I want to switch to “game” layout, but nothing happens. Any tips?

    Also, if you want, feel free to give any tip to improve any aspect of my programming!

    Thanks to the C2 developers, to the community and thanks for your time!

    Tagged:

  • For your issue with the button on the menu layout, you can see in the properties of the layout that no event sheet is associated to the layout, so no code is set to happen.

    Do change the "Event sheet" property to "Event sheet 1" and your "menu" layout will take you to your "game" layout.

    In your event 37, only the Buid object you are clicking is selected and you can then set a destroy action at the end of that event to delete this Buid instance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For your issue with the button on the menu layout, you can see in the properties of the layout that no event sheet is associated to the layout, so no code is set to happen.

    Do change the "Event sheet" property to "Event sheet 1" and your "menu" layout will take you to your "game" layout.

    In your event 37, only the Buid object you are clicking is selected and you can then set a destroy action at the end of that event to delete this Buid instance.

    I see. That way I would destroy the sprite. The problem is that as you can see I have also programmed a cancel option (events 39-41, when pressing scape or right click). Its my fault, i havent explained my self correctly. Once you click a "build" sprite two new images appear. "ImageTower1" and "ImageTower2". I have only programed the Tower 1 so if you click on that one a new Tower is created and "ImageTower1" and "ImageTower2" move out of the layout. But imagine that I click one "build" sprite to build a new tower, the two tower images pops up and suddenly I change my mind and I want to create it on another place, so I cancel the building pressing Scape or right-clicking. That means that the "build" sprite has to still be there for a future tower. What I mean is that the "build" sprite has only to be destroyed if we have built a tower on it, not just when we click it.

    Sorry for the misunderstood. Really sorry. I hope someone can help me, thanks.

  • I took a look at your capx.

    I couldn't get the demo to do anything, but....

    Create a variable: "temp_Build_UID"

    Event 37

    When a player clicks a "build object", add a piece of code:

    set global variable >> "temp_build_UID" to build.UID

    // this lets the game remember which build tower was clicked last.

    Event 38

    then, in the event where the tower is built, add another condition

    pick the Build object by UID >> then use the temp_build_UID variable

    // this has the game pick the build tower that was last clicked

    In the same event, add a piece of code:

    destroy "build object."

    // this destroys the last clicked build object.

    hope that helps!

  • Then you are not looking to destroy instances.

    Instead you may rather need to add an instance variable (boolean) to your "Build" sprite.

    Let's name it "built" for example. Have it being of value false by default.

    When you do build on the sprite, set the instance variable "built" to true.

    You can do that in event 37 as mentioned previously since the instance is being picked.

    You now have also access to the condition "Build boolean instance variable built is false".

    When you add this condition to some event (for exemple event 37, again, which is the "building" event) if the clicked Build has already been built, then the action to build on it won't happen.

    When you are cancelling/destroying the building built, make sure to change back the "built" value to false, to allow later building on the Build sprite.

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