Author Topic: Drawing a Line  (Read 2681 times)

mutantandy

  • Member
  • **
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Drawing a Line
« on: Wed, Jun 6, 2012 »
Hi,

I've been looking at drawing a line today.  Basically I need to draw a "laser" that shoots from a "laser cannon" which can move and/or rotate.  Now, in my naivity, I assumed that a single pixel scaled along x to the width required would be the way to go, but alas, when rotated, the scale multiplier remains along the x axis and does not rotate with the sprite, giving an awkward effect.

Before embarking on a lengthy mission of trial and error to find the best way, I thought I might ask around and see if anyone has done anything like this before on iOS, or if anyone with more experience can shed some light on the most optimal practice going forward. 

As far as I can see, I have the following options:
1. FlxGroup - I could draw many single pixel objects along a line, throw them all in a group and then rotate that group around a fixed point.  Aliasing may be a bit tricky here, but it does offer some versatility for bending the line...
2. OpenGL - I could go deep and draw the line using openGL.  I only really want to do this as a last resort as this may take quite some time.  Also, I will need to write a seperate collision detection algorithm for this, which won't be overly difficult.  Also it would be nice to make this versatile enough that anyone could use it with a single pixel image.
3. Long-line pre-rendered - I could make a long line, and then mask the line by editing FlxSprite.width.  This seems to me to be the easiest option, but probably uses the most memory.

It's my first post, so hopefully people will find this useful/intriguing.

Cheers,

Andy


mutantandy

  • Member
  • **
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Drawing a Line
« Reply #1 on: Mon, Jun 11, 2012 »
OK, so I found the easiest way to get this working quickly is to use option 3.  I've made a sprite thats the size of the screen (corner to corner) and then I use sprite.height to adjust the amount shown.

I have hit another snag now, when I rotate the laser the collision detection will of course not rotate as well, so now I think I'm going to need to adjust FlxObject to take the rotation into account.  I'm working on this today so will hopefully be able to post up what I come up with soon.  I'll post it up in another topic called rotational collision detection or something as it isn't really relevant to this line drawing one.

If anyone can shed more light on the drawing line problem then I am still very keen to hear them. The method I've chosen is particularly memory heavy and probably not best practice.

Andy