How to get a UIButton to fire mutiple shoots

Discussion in 'Public Game Developers Forum' started by CladCreations, Mar 7, 2009.

  1. CladCreations

    CladCreations Member

    Feb 23, 2009
    14
    0
    0
    Im trying to make a shooter type game need some help to get m air plane to shoot???????
     
  2. StandAlone

    StandAlone Member

    Jan 28, 2009
    5
    0
    0
    Chicago
    You probably don't want to use a UIButton for this, but rather a standard UIView, and override touchesBegan/touchesEnded.

    B
     
  3. #3 wastedyuthe, Mar 24, 2009
    Last edited: Mar 24, 2009
    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.
     
  4. CladCreations

    CladCreations Member

    Feb 23, 2009
    14
    0
    0
    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!
     
  5. WellSpentYouth

    WellSpentYouth Well-Known Member

    Jan 11, 2009
    1,363
    0
    0
    iPhone programmer
    App Tech Studios, USA
    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.
     

Share This Page