1
votes

I'm trying to make a little archer game, and the problem I'm having has to do with 2 pixels in particular, I'll call them _arm and _arrow. When a real archer is pulling back an arrow, he doesn't immediately pull the arrow back as far as his strength allows him, the arrow takes a little bit of time to be pulled back. The _arm's angle is equal to the vector from a point to where the user touched on the screen. The rotation is perfect, so the _arm is good. The _arrow needs to be on the same line as _arrow, they are 1 pixel wide each so it looks as though the _arrow is exactly on top of the _arm.

I tried to decrement from the x/y coordinates based on a variable that changes with time, and I set the _arrow's location equal to the _arm's location, and tried to make it look like the _arrow was being pulled back. however, if you rotated, the x/y would mess up because it is not proportional on the x and y axis, so basically _arrow will either be slightly above the arm or slightly below it depending on the angle of the vector, based on touch.

How could I used the x/y position of _arm and the vector of touch to make the arrow appear as though it was being pulled back by a small amount, yet keep the arrow on top of the _arm sprite so that it's position would be similar to the arm, but slightly off yet still on top of the _arm pixel at all times. If you need anymore info, just leave a comment.

1
Do I understand it correctly that you are trying to extrapolate a line defined by two points? - Dabbler
No. Sprites's location is based on the center of the image. So if both are 20px long/1px wide, and I set arrow.position = arm.position, then they are exactly on top of each other. I want a way of finding the x/y points based on angle of the arm sprite, like for instance at a 45 degree angle, it might be .75 pixels down.x and .75 pixels down.y, I would set the arrow's position to that point and decrement that to make it look like it's being drawn. - Gabriel

1 Answers

0
votes

I'm not sure I've fully understood, but I'll have a go at answering anyway:

To make the arrow move and rotate to the same place as the consider adding the arrow as a child of the arm. You can still render it behind if you like by making its z is less than one: [arm addChild:arrow z:-1]

To then make the arrow move away from the arm as the bow is drawn, you then just set the position of the arrow with respect to the arm.

The problem I do see with this solution however is that this grouping of the sprites may be a little unusual after the arrow leaves the bow. Here you probably don't want the arrow to be a child of the arm as the coordinate systems are no longer related.

Even though they're sure what I "suggested would have solved [the] problem" here is the

Poster's solution

I had to get the x and y coords of the arm based of angle, then I got the sin/cos of a number that was based of the same angle as the arm and subtraced from that.