Peter's idea sounds like a good one to start with to try and see if
you like it.

For the best realism though I think a bitmap would be the solution.
You don't have to rotate the bitmap - just make a bitmap that is known
as a "billboard" (google billboarding graphics), with some alpha in
it. (Although maybe the alpha will slow render time way down, don't
know). Then you just do a quick loop from point A to point B,
calculate the positions yourself (use slope of the line equations) and
blit the bitmap over and over. You can also have two bitmaps, one
pulsed and the other not, and then just cycle between them at a
determined rate. The blitted bitmaps will overlap each other and form
a type of particle beam effect.

Although for a laser maybe Peter's solution is best, my bitmap idea
would be more like a particle beam type thing.

I've used this technique to create lightning for a game I wrote a long
time ago in C#, worked really well. (To create lighting I randomized
some of the points between A and B to move around)


-niko

On Feb 3, 8:05 pm, Peter Webb <r.peter.w...@gmail.com> wrote:
> I bet you can make a pretty funky laser beam using the draw lines or
> fill polygon commands in the Canvas/Paint library.
>
> To draw basic unpulsed laser beam draw a transparent line of width 6
> between a and b. Then draw on top an opaque line of width 2 between a
> and b. You will get an effect where the laser beam falls off in
> brighness from the centre to the edges.
>
> To pulse it, draw a short line segment of width (say) 8 on top of the
> unpulsed laser beam, and move its position between a and b every
> screen refresh so the pulse moves along the line.
>
> If you want your laser beam to be some shape other than a long thin
> rectangle, you can do the same thing with a polygon fill command and
> you can have the laser beam whatever shape and size you want.
>
> On Feb 3, 7:38 pm, Mando <mando.aka.ch...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi, hope this is the right location to post this.
>
> > I am working on a 2d android game with a light space shooter theme. I
> > wanted my ship to have a turret the that tracks targets, rotates and
> > fires a laser beam that is animated (maybe pulsing or with non uniform
> > bulges issuing out of the turret and moving down towards the target).
>
> > Key parts of the problem. laser starts at 1 coordinate and terminates
> > at another in 2d space and could be of arbitrary length (might be
> > scaled if I decide to add zooming).
>
> > Possible brute force solutions:
> > 1) using rotation/transformation to manually draw a bitmap
> > representing a segment of laser all along the required distance.
> > (cycling the bitmap as required for animation)
> > 2) Create a very large laser beam image (longer than I would need eg:
> > 10px by 500px) and draw it at correct transformation.
>
> > Looking at the BitmapShader and reading some of the SDK info about
> > Paths, Paints etc it feels like there should be a better way to do
> > this, but no examples I've found covers it.
>
> > Any idea if there is a way to use a BitmapShader to paint using a
> > canvas.drawLine or canvas.drawPath call to create this effect?
>
> > Thanks in advance
>
> > Mando

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to