Hi everybody,
I'm new in iPhone's developments but not in developments.
Actually I have a two problems :
- Positionning an object on the screen
- Shoot in one direction.
The player can move himself on the screen with his finger, so basically he will drag his avatar on the screen with his finger. That is pretty easy to do with cocos2d.
I need to position a cross next to the avatar by following this basic rules :
- when the player go left, the cross will be at his right
- when the player go up, the cross will be at his bottom
- when the player go right, the cross will be at his left
- when the player go down, the cross will be at his top
- the cross need to be at a constant distance from the player
I can create a code for this basci code, but I want to be able to manage multiple movement like :
- go up and left in the same time, the cross will be at the bottom right of the player and at an unique distance.
That is he hard part of my problem, I try many algorithm an nothing want to works.
The only thing who works "properly" is the easing technics with the player position, but if you move to fast the distance between the player and the cross will not be constant and some time you can have the player on the top left of the screen and the cross on the bottom right of the screen...
My second problem is related with the first one.
I want my player to shoot a ball in the direction giving by his position and the cross position !
So basically the player will shoot in the exact opposite direction than his movement.
I was able to get the vector between the player and the cross, after that I can say that I want a movement between the player position and X times my vector (x in a constant) in Y seconds. Thats works.
But I would like a variation of that, I want to be able to shoot 3 balls one in the opposite direction, one other with -5° and the other one +5°.
I have no idea how I can do that !
Could you help me for that ?
PS : I'm sorry for my english, it's not my main language ;)