I need help with an explode on tap script
by michael walton · in iTorque 2D · 08/19/2011 (2:54 pm) · 3 replies
Hi everyone! :) I'm new to making video games and but I'm working on a game now
For the iPhone So one thing I need to know is how to make things explode when you tap them?
Good example would be let's say a stationary enemy shots rockets at you
And you can destroy those rockets when they get to a certain point. If you press to early
Or miss and let it pass by you lose life but if you tap it on time the enemy takes damage
This is what I'm looking for so thanks in advance for the help :)
For the iPhone So one thing I need to know is how to make things explode when you tap them?
Good example would be let's say a stationary enemy shots rockets at you
And you can destroy those rockets when they get to a certain point. If you press to early
Or miss and let it pass by you lose life but if you tap it on time the enemy takes damage
This is what I'm looking for so thanks in advance for the help :)
#2
1.5 will ship with a large library of example behaviors and demos that include stuff like this.
08/19/2011 (6:38 pm)
The above is just one possible way to perform what you are asking for. It's probably the simplest solution, but it can be expanded on to include lives, special effects, color tinting, etc.1.5 will ship with a large library of example behaviors and demos that include stuff like this.
#3
08/19/2011 (10:54 pm)
That looks great!!! thanks a lot! when i get a chance to test it out i'll let ya know how it goes. I will also check out all the other stuff you told me about. Thanks again for the help.
Employee Michael Perry
ZombieShortbus
This can easily be achieved using behaviors. If you are using any of the 1.5 previews, you can use the following code:
1. Create a script called touchDownDestroy.cs
2. Add that to the YourGame/projectFiles/game/scripts/behaviors directory. If that folder does not exist, create it first.
3. Open the script and add teh following:
if (!isObject(TouchDownDestroy)) { %template = new BehaviorTemplate(TouchDownDestroy); %template.friendlyName = "Touch Down Destroy"; %template.behaviorType = "Game"; %template.description = "Inflict damage when this object is touched"; %template.addBehaviorField(health, "The amount of health this object has", int, 30); %template.addBehaviorField(damage, "The amount of damage to apply", int, 10); } function TouchDownDestroy::onBehaviorAdd(%this) { // Enable touch events %this.owner.setUseMouseEvents(true); } function TouchDownDestroy::onTouchDown(%this, %touchID, %worldPos) { // Take damage %this.health -= %this.damage; // Check to see if it has died if (%this.health <= 0) { // Do special effects here // Delete the scene object %this.owner.safeDelete(); } }