Closed davidyu closed 10 years ago
Here's a simpler implementation:
Question: after the leading point travels some distance (let's say y), it fades or expires. Does the trailing point follow -- IE: it travels y-x distance, or does it keep going and travel a total of y distance as well?
Answer: use timed effect and expire all points at the end of some time! Perfect.
Overall requirements:
Solutions
Instead of connecting and maintaining multiple points, use Flash's bitmap and blending functionality to simulate the appearance of a trail.
How to actually do this?
Naive method (done in 28d468ab698043e935d7f4c925929675ecd9ad89):
Draw the point onto a bitmap (maybe a circle with a small 2-pixel radius) - tried in 3ad6eb9417a18d95b41bd001dc866880ca454770, this still leaves gaps Next time I draw, multiply the alpha of all pixels on the bitmap by 0.9 (apply a ColorTransform) Draw the point. And so on and so forth.
With Brensenham's line-drawing algorithm to fill in the gaps (done with c6afa2f6bf1e7408c034c297e9c3d3ae96a1c910 and 1f03d66ea47ed47b6531962d1b366704d7d43a25):
Draw a line between the current pos and the previous pos using Brensenham.
Pros: much simpler to implement Cons: some annoyances with a proper camera. Bitmap sprites are noticeably more memory intensive so we cannot create a bitmap as large as the entire world. Instead, we create one that fits the viewport/screen and move that and the contents within it as the camera changes.
Clean up work:
Define a maximum distance for this unidirectional sonar. Use mouse to aim.
Thoughts on implementation:
Use the point of origin of sonar and the cursor's position to define a ray. Do line-line intersections. If it hits an edge, create an incident ray and continue to do line-line intersections for that ray. Keep going until the max distance is exhausted. Return the ordered list/array of line segments that define the path of this sonar.
Followup: implement aim cursor