iDevGames Forums
give direction to sprite - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: give direction to sprite (/thread-8712.html)



give direction to sprite - termitis - Mar 10, 2011 09:19 AM

Hi! I have a sprite which i move by touching it...i drag it all around the screen an d when i leave it I want it to move to the direction wheew my hand was moving...I mean...drag and move,leave it,continue moving to the direction pointed by me.


RE: give direction to sprite - compiler - Mar 10, 2011 11:26 AM

You want to find the velocity vector of the sprite and you know two vectors:

- position of sprite
- position of target

Google vector subtraction.


RE: give direction to sprite - termitis - Mar 10, 2011 12:40 PM

Thanks but what should i use?BOX2d?Im new and I have no idea..any help please!!


RE: give direction to sprite - ThemsAllTook - Mar 10, 2011 02:04 PM

The problem as stated wouldn't require a physics engine like Box2D, just some simple interpolation/velocity code. We'll be able to help you more if you post some detailed information about what you're trying to do and what's giving you trouble; there isn't a whole lot to go on from what you've posted so far.


RE: give direction to sprite - termitis - Mar 10, 2011 03:36 PM

Im sorry but i I cant post code..what i want is when touch ended method gets called,the code will have "saved" the direction to which my hand was pointing before i release the sprite and then to automatucally continue moving the onject to that direction.


RE: give direction to sprite - compiler - Mar 10, 2011 04:23 PM

Are you new to programming? Games? iPhone programming? You're going to have to write code in a computer language to accomplish what you want. Programming isn't something you can just decide to pick up one day and start cranking out games.


RE: give direction to sprite - hemi - Mar 11, 2011 02:27 AM

(Mar 10, 2011 11:26 AM)compiler Wrote:  You want to find the velocity vector of the sprite and you know two vectors:

- position of sprite
- position of target

Google vector subtraction.
its a nice info man..!!! i wasnot knw about it....


RE: give direction to sprite - compiler - Mar 11, 2011 07:03 AM

So if a is the position of the target, and b is the position of the sprite...

[Image: Vector_subtraction.png]


RE: give direction to sprite - johncmurphy - Mar 11, 2011 02:17 PM

compiler - what program did you use to make those arrow images?


RE: give direction to sprite - compiler - Mar 11, 2011 02:38 PM

(Mar 11, 2011 02:17 PM)johncmurphy Wrote:  compiler - what program did you use to make those arrow images?

Google. :-)