Laser Beam using textured segments?

Problems with Canvas, OpenGL, etc...

Laser Beam using textured segments?

Postby isam2k » Sun Aug 21, 2011 9:46 pm

Hi all,

im new to this forum so please forgive me that im starting off asking questions to you guys.

Im currently working on a real-time strategy game for android and im making quite some progress. The graphics (units, bases, etc.) are animated 2d sprites and it all seems to work pretty well so far.
But now i have encountered a problem to which i'm aparently unable to find any good (performant) solution.

The problem is, that i want to add shooting animation to the game. A firing unit is pretty easy, but let's say for example, that i have a spaceship that fires a laser beam towards its target. The beam should be animated and of course can be of variable length, as units usually have a specific firing range in which they can hit a target.

So its pretty much impossible to use a specific animated sprite for that beam, as it would be of a constant length.

My first idea was to create animated beam-segments which i put together to create beams of variable length. Depending on the length of those segments, this can be pretty bad in terms of performance if (for example) i had to draw a laser beam of very long length, which would result in a lot of textured triangle fans i would have to render.

My next idea was to first determine the length of the beam i would have to render, on a next step i would create a bitmap of that specific length and draw the beam segments in that bitmap. Then of course i would create a texture with that bitmap and draw it upon a triangle fan. BUT, as those beams are animated, this solution as well seems to be pretty bad in terms of performance.

I think, that the best solution for now would be my first idea, using beam segments of, lets say 8-16 pixels in length. This would cause the beams to be slightly too long or too short, but i think for now thats really my best bet.

Or does anyone have any ideas on how to solve that particular problem in a better way?

Thanks in advance.
Posts: 2
Joined: Sun Aug 21, 2011 9:16 pm


Re: Laser Beam using textured segments?

Postby millerni456 » Fri Oct 07, 2011 12:48 am

I do have an idea.
I'm not sure how it affect performance, but it's worth a shot.

Create 1 rectangle that goes from the laser emitter to the target.
On this rectangle the Texture image should stretch/repeat based on your settings.
So for the most part of calculations, you'll need to determine the repeats of the texture and the size/orientation of the rectangle.

And if you want to get fancy, you can update this Texture image to provide an animation.

So I didn't think you would need more than 2 Triangle_Strip segments.

I hope this helps. -Nick.
Junior Developer
Junior Developer
Posts: 12
Joined: Wed Oct 05, 2011 12:39 am

Re: Laser Beam using textured segments?

Postby roopa » Thu Oct 20, 2011 12:34 pm

This is one of the most incredible thread Ive read in a very long time. The amount of information in here is stunning, like you practically wrote the book on the subject. You have great information for anyone who wants to understand this subject more. Great stuff; please keep it up!
Posts: 27
Joined: Wed Sep 14, 2011 6:46 am


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 3 guests