Author Topic: filling an area with a sprite?  (Read 966 times)

zez

  • Active Member
  • ***
  • Posts: 203
  • Karma: +0/-0
    • View Profile
    • Devlog
filling an area with a sprite?
« on: Wed, May 19, 2010 »
So, my problem is basically this, Im trying to set it up so that there is water in the game Im working on. I need the player to be able to go both above and under the water, and have it have some effect on movement and such. Im thinking Im going to use a semi transparent sprite for the water itself, and use FlxU.overlap to modify the movement well under it. That part isnt tooo tricky at all, but it would be nice if there was a way to basically make the water fill an area. I know I can get it to basically make a giant rectangle using scale and adjusting the height and width to the final values, and I can even use getTile to figure out where to make the rectangle stop forming, but is there a good (by good, I mostly mean CHEAP) way to make it then create more sprites to fill the rest of the area (any area that is say, not in the rectangle?)
Maybe I could loop around the corners and make more water sprites that also fill a rectangle when its done? That seems like it would WORK, but might lead to tuns of sprites if there is a particularly oddly shaped underwater area...
Is there a way to generate non rectangular flxsprites I just dont know about?
It would be pretty easy to generate an array that was basicly "every square that water could possibly be" and fill that in with 16x16 squares, but then I would either need to make a billion tiny sprites and destroy my fps (I think... I mean... moves = false might go a long way, but still) or use draw to make a giant sprite, but then it would still actually be a rectangle, and the player would no doubt end up underwater at inappropriate times by overlapping transparency...

Garmichael

  • Member
  • **
  • Posts: 89
  • Karma: +0/-0
    • View Profile
Re: filling an area with a sprite?
« Reply #1 on: Wed, May 19, 2010 »
When I made my laser beam, I gave it a bitmap fill. It required drawing to the buffer and overriding the render function. That thread had my code in it, but if you're already aware of how to make buffer-rendered objects, you can use this code:

Code: [Select]
[Embed(source="PathTo/WaterTexture.png")] private var IMG_Water:Class;

Then, inside your render override:
Code: [Select]
var pattern:BitmapData = FlxG.addBitmap(IMG_Water);
canvas.graphics.moveTo(newOrigin.x, newOrigin.y);
canvas.graphics.beginBitmapFill(pattern);
//Do your LineTo or Rectangle or whatever drawing you want.
canvas.graphics.endFill();