Hi to all,
In my game there is a hurdle between player and enemy. Can I detect it that there exist a hurdle between them.? any build in function that can be used to do this.
thanks in advance
cocosboy
A fast, easy to use, free, and community supported 2D game engine
Hi to all,
In my game there is a hurdle between player and enemy. Can I detect it that there exist a hurdle between them.? any build in function that can be used to do this.
thanks in advance
cocosboy
Well, depending on your setup, you may be able to do check if the hurdle's position.x lies between the player's position.x and the enemy's position.x.
Pseudo code:
if (player.position.x > hurdle.position.x > enemy.position.x)
{
// If the hurdle is between, then execute this block!
};
Sorry I forgot to mention.
if we have to compare 200 hurdles that can be in between them. All hurdles are Sprites of size 5x5.
Then we will have to compare all of them? (that I don't wish to do)
If iPhone processing don't have problem in processing this big processing then I can use this?
I was thinking to find some short way or built in function to do it.?
but confused what to do? :)
I am thinking to use chipmunk for that, as missile have to be used for enemy and player.
any suggestion?
I think that the only way to quickly do that check is to keep track of pertinant information as you go so that when you need to check something (like which hurdles are between the player and enemy).
You could maintain an array of hurdles between the player and enemy every time your game updates everything's position. Since you're likely looping through all your game's sprites, you could just test if each hurdle is between or even likely to be inbetween the player and enemy and vastly reduce the number of hurdles you need to test when you're actually checking if 1 is between the player and enemy (just check for that hurdle in the array, and if it's not there, it isn't between them).
You must log in to post.