Author Topic: Tiling an image possible?!  (Read 1089 times)

noFunk

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Tiling an image possible?!
« on: Fri, Jan 20, 2012 »
Hi Guys
Quick question I hope someone can help me with. Is there a way of tiling an image inside flxSprite?

I have electric floor sections in one of my levels, these sections are various lengths from 32px up to around 320px. I have an animated  image which is 32px wide, its seamless so can just be tiled along x no problem.

I know I could use flxGroup like this for example
Code: [Select]
var i:int = 0;

while (i < width)
{
var tempBolt:FlxSprite = new FlxSprite (x + (i * 32), y);
tempBolt.loadGraphic(electricPNG, false, false, 32, 16, false);
add(tempBolt);
i++;
}

but this causes problems because I have metal blocks that can bridge gaps in the electric to complete a circuit

Any ideas if its possible to just tile a texture?

Foxtacy

  • Aspiring Indie Game Developer, Prototype Musician, Lame Pixel Artist
  • Member
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
    • Need songs? :3
Re: Tiling an image possible?!
« Reply #1 on: Fri, Jan 20, 2012 »
If i understood your question right...

I think maybe, you might prefer to make your sprite animated, or, draw an animated sprite over a tile.

to get the tile you might have to do something like:

map.getTile(i,y) // Note: x,y not in pixels, but in tile indexes.

var tempbolt = new FlxSprite(i*32,y);
tempBolt.loadGraphic(electricPNG, false, false, 32, 16, false);
add(tempBolt)
i++;

I know for sure, that there is a better way to do this. I mean, you CAN create animated tiles, i just don't know, but i know there's a way to do it on flixel...

Maybe you should look out DAME or the flixel API to figure out how to do it: http://flixel.org/docs/
Waiting is wasting

noFunk

  • Member
  • **
  • Posts: 45
  • Karma: +0/-0
    • View Profile
Re: Tiling an image possible?!
« Reply #2 on: Fri, Jan 20, 2012 »
Thanks for the reply

I did consider using an animated tile but I don't think its appropriate for my game, as I need a variable attached to each section to say if the power is on or off

Basically if a section has the power turned on and a metal block touches it, it becomes electrified. Then if the block is touching another section at the same time its power is turned on, in a chain reaction kind of style.

I have it all working with just a blue box rather than a texture
Code: [Select]
public class ElectricChargeOnOff extends FlxSprite
{
public var ElectricOn:Boolean = false;

public function ElectricChargeOnOff(X:Number, Y:Number, WIDTH:Number)
{
super(X, Y)
makeGraphic(WIDTH, 16, 0xff0079FF);
}

override public function update():void
{
super.update();

if (ElectricOn)
{
visible = true;
}
else
{
visible = false;
}
}
}

Now I need to have my sprite instead of the blue box. I just need a way of saying repeat the sprite X number of times

Foxtacy

  • Aspiring Indie Game Developer, Prototype Musician, Lame Pixel Artist
  • Member
  • **
  • Posts: 29
  • Karma: +0/-0
    • View Profile
    • Need songs? :3
Re: Tiling an image possible?!
« Reply #3 on: Fri, Jan 20, 2012 »
Maybe you could use the "exists" or "alive" boolean flags to do so! then you could revive() when you want it on, and kill() when u want it off :D!

this flag is present on all the objects, bcuz it's on FlxBase or FlxObject, the most primitive types on flixel :)
Waiting is wasting