Tap to shoot - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Tap to shoot (/thread-886.html)
Tap to shoot - 9livesoftware - Aug 7, 2009 09:23 AM
I'm making a shooter game and was wondering, how do you make it so when you tap on the screen the bullet goes towards where you tap. Also I wan to make my own speed for the bullet. Lastly when the bullet gets to where the user taps how do I import an explosion animation? Thanx for help
Tap to shoot - kendric - Aug 7, 2009 12:49 PM
Step 1 record the x,y the tap happened at from the touch even
Step 2 create a bullet where you want it to start
Step 3 in your main game loop move the bullet towards Step 1's value
in a speed of your choosing
Step 4 You will need to choose a rendering engine and figure out how to draw animations. Check out coscos2d for opengl
It sounds like your asking how to do things that you think will be simple but that you may not have a solid background in programming. If that is correct this is a complicated way to start learning.
Tap to shoot - smasher - Aug 7, 2009 01:10 PM
I'm going to assume that you're making a shmup like r-type or space invaders, where bullets are real objects and you can dodge shots. In other games - like doom and starcraft - damage is automatic, bullets are more like special effects, and no collision detection is used.
Your game probably already has an array of game objects that you call an "update" method on every frame. You just need to create a "bullet" object and add it to the array.
When it's created, the bullet needs to know:
*it's own position
*its speed and direction, probably in the form of two numbers - speedx and speedy. You can express any direction+speed with those two numbers.
The "update" method for the bullet needs to do this:
(1) move the bullet to the new position by adding positionx+=speedx and positiony+=speedy.
(2) check the new position against every object in the object list
(3) if you find a collision, remove the bullet from the list and damage the object it collided with.
EDIT: rereading your message, I see you need the formulas to find speedx and speedy based on the touch point. Here's one way to do that.
(1) get the distance from the gun to the target (pythagorean theorem.) You'll also calculate deltax and deltay in the process.
(2) divide the distance by the speed of the bullet (the amount to moves every frame.) This gives us the number of steps.
(3) speedx = deltax / steps. speedy = deltay / steps.
The "delta" means difference; so for example deltax is the difference between the x position of the gun and the x position of the touch.
Tap to shoot - 9livesoftware - Aug 8, 2009 09:14 AM
Could you guys give me a source code or an example project on this becuase it is kind of confusing. Thanx
Tap to shoot - ThemsAllTook - Aug 8, 2009 09:53 AM
9livesoftware Wrote:Could you guys give me a source code or an example project on this becuase it is kind of confusing. Thanx
That would be doing you a disservice. Being able to solve this sort of problem from your own understanding is fundamental to programming. If someone hands you a working solution and you just use it, you've learned almost nothing and you're stuck back at the same place next time you need to solve a problem like this. You become completely dependent on outside help for the most basic of tasks. I've seen it happen more times than I can count.
Read up on the basics of programming, if necessary. If you get stuck and need some specific help, come back and ask, but this is too fundamental and broad. We can't write all of your code for you. You won't be able to piece together a complete application from random snippets of code on the web without understanding how programming really works.
Tap to shoot - 9livesoftware - Aug 8, 2009 10:04 AM
Could you give me a tutorial or helper video?
Tap to shoot - FlamingHairball - Aug 8, 2009 10:32 AM
9livesoftware Wrote:Could you give me a tutorial or helper video?
ThemsAllTook Wrote:Read up on the basics of programming, if necessary. If you get stuck and need some specific help, come back and ask, but this is too fundamental and broad. We can't write all of your code for you. You won't be able to piece together a complete application from random snippets of code on the web without understanding how programming really works.
Nobody wants to help someone who isn't willing to do a bit of work themselves. I'm not acquainted with iPhone dev, but I'm fairly certain there are plenty of resources online to get you started. Do some Googling, even search the iDevGames front page, and you should be able to get a start on the iPhone.
Tap to shoot - 9livesoftware - Aug 11, 2009 10:26 PM
I finished the hard part of the tap to shoot but need some help. I made a line to where ever you tap and when you tap it goes there and deletes itself afterwards can you tell me how to import a bullet instead of the line?
Tap to shoot - Oddity007 - Aug 12, 2009 04:43 AM
Kendric described this perfectly in his first reply.