★ TouchArcade needs your help. Click here to support us on Patreon.

How to get a UIButton to fire mutiple shoots

03-07-2009, 06:42 AM
#1
Joined: Feb 2009
Posts: 14
How to get a UIButton to fire mutiple shoots

Im trying to make a shooter type game need some help to get m air plane to shoot???????

My First App is almost Done!
Games I'm Playing: SpaceX: Space Ninja: Pocket God: Geo Defense: Light Bike: iShoot;
03-23-2009, 12:56 PM
#2
Joined: Jan 2009
Location: Chicago
Posts: 5
You probably don't want to use a UIButton for this, but rather a standard UIView, and override touchesBegan/touchesEnded.

B
03-24-2009, 07:03 AM
#3
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
I have used this for my own game (but not for firing a weapon), where the player can actually hold down a button in order for them to keep doing what that button does.

CladCreations can do the same thing.

When you set your IBAction for your button, in Interface Builder, instead of using the "Touch Up Inside" option, use "Touch Down". This will detect if you are holding down on that button rather than detecting if you have released your thumb off it.

Then in your IBAction Method you have associated with it, you can set what ever variables you like to say you are firing your weapon, and if it already firing.

You would probably need a seperate IBAction method though for associated with "Touch Up Inside", for when you do release your thumb off, so it stops firing.

Last edited by wastedyuthe; 03-24-2009 at 07:06 AM.
02-12-2010, 12:03 AM
#4
Joined: Feb 2009
Posts: 14
Quote:
Originally Posted by wastedyuthe View Post
I have used this for my own game (but not for firing a weapon), where the player can actually hold down a button in order for them to keep doing what that button does.

CladCreations can do the same thing.

When you set your IBAction for your button, in Interface Builder, instead of using the "Touch Up Inside" option, use "Touch Down". This will detect if you are holding down on that button rather than detecting if you have released your thumb off it.

Then in your IBAction Method you have associated with it, you can set what ever variables you like to say you are firing your weapon, and if it already firing.

You would probably need a seperate IBAction method though for associated with "Touch Up Inside", for when you do release your thumb off, so it stops firing.
Thnx for the reply! I am wanting to animate some bullet sprites I kinda know how this is done. but how do you detect a collision with the enemy and make the bullets go across the screen. I cant seem to find anybody that will help me out with this! thanx for any help you can give!

My First App is almost Done!
Games I'm Playing: SpaceX: Space Ninja: Pocket God: Geo Defense: Light Bike: iShoot;
02-12-2010, 12:44 AM
#5
Joined: Jan 2009
Location: App Tech Studios, USA
Posts: 1,363
Quote:
Originally Posted by CladCreations View Post
Thnx for the reply! I am wanting to animate some bullet sprites I kinda know how this is done. but how do you detect a collision with the enemy and make the bullets go across the screen. I cant seem to find anybody that will help me out with this! thanx for any help you can give!
It has been awhile since I have used Xcode exclusively, but I think that this line of code from Aerial Combat should detect if one object is touching another:

Code:
	if(fabs(self.bullet.center.x - self.boat.center.x)<self.boat.frame.size.width/2.0 && fabs(self.boat.center.y - self.bullet.center.y)<10.0) {
Of course replace bullet and boat with the name of your bullet and your target object. You may need to change the numbers to fit your game, but that should get you going.

As far as moving an object, use these lines:

Code:
CGPoint PI2Center = pi2.center;
	PI2Center.x += 10;
You can change the .x to .y and you can change the 10 to any number you want. Put this in an NSTimer to fluiding move an object across the screen Just so you know, it doesn't matter what the CGPoint is called (PI2Center in the example), but what you put just before .center must be the name of your object.