Draw Sprite Between Two Points

Could anyone point me in the right direction on how to draw a sprite between two points? Similar to a spline. I’ve looked all through the API, google searches, etc., and can’t a good starting point to figure it out. The sprite I want to draw between two points is also sliced.

Thanks!

can you please post a picture of what you’re trying to achieve?

I’ve dumped the idea mechanically because it wasn’t important enough for my game. It would be great to add though. The best I can do is describe what I was trying to do, and it’s simple. A ‘laser beam’ from the firing point (player) to the enemy. At first I tried scaling the beam based on the collision, but then I couldn’t find where to get the actual collision point; it’s just a collision test (please let me know if I’m wrong and can get the point of intersection).

Therefore, I figured it would be best to draw the ‘laser beam’ from the start point to the end point. This way I can change the ending point based on collision, and the tiling sliced sprite would just draw correctly between the starting point and ending point.

I randomly ran into a document on the graphics component that looked promising, but as I’ve said, I’ve dumped the idea for this project so I’m not in a position to do trial and error. Perhaps on an update. I really did want laser beams.

Thank for your reply, Karg.

oh, lasers :slight_smile:

you have a couple of options here: one is to use cc.Graphics and draw lines. you would have to translate the start and end points to the local coordinates of the node with the cc.Graphics component, then draw the line.

the other is to use the laser beam sprite and size the node width to the distance between start and end points of the laser. then you would have to rotate the aforementioned laser beam to correct angle (determined by the start-end points) and translate the beam to the start.

1 Like

Yep, I think cc.Graphics is the way to go, because I was originally working with node height, and it was just overly difficult. I was able to get the box collision to play nice. Since the collisions; as far as I still know at this moment; do not give a point of intersection, it was hard to calculate node height. I used the height of interaction (hit object height), adjusted height of the ‘laser’, adjusted scale of the canvas, adjusted box collision scale; but it still wasn’t visually accurate enough. It looked really cool, but wasn’t accurate. Not to mention, I’m a programmer, and the entire mechanic I had in place probably could have worked if there was some good art, lololol.

Thanks for the help, Karg. I appreciate it.