Page 1 of 1

Tilable Regions

PostPosted: Thu May 22, 2008 4:23 pm
by Cleve Blakemore
It would be great if you could set an actor to X/Y infinite, make a region it's parent, then specify to clip the edges of that repeating texture within the region. This would permit a lot of effects on screen possible like scrolling credits inside a viewport, etc.

Re: Tilable Regions

PostPosted: Mon Jul 07, 2008 1:42 am
by feral
sorry, came across this old request and seemed worth answering...
tiled_regions.jpg

Creating a x/y infinite tiled "region"

1. create a Actor (Normal) called wallpaper (or your choice of name) and add an animation

2. create another Actor (Canvas) and in the Create Actor event of the canvas actor insert following

Code: Select all

int i,j;

for (i=0;i<width;i=i+wallpaper.width)
{
  for (j=0;j<height;j=j+wallpaper.height)
  {
  draw_from("wallpaper",wallpaper.width/2+i,wallpaper.height/2+j, 1);
  }
}


1. is that what was wanted ?
2. if you want to change animations in mid game (after create actor) place code in the canvas's "Draw Actor" event but use a "flag: variable or something, so it only redraws when needed.
3. is there any way to use draw_from in a global script ? So I can create a function called wallpaper() to do this automatically ?

feral

Re: Tilable Regions

PostPosted: Mon Jul 07, 2008 2:05 am
by feral
I just had another thought.

The above script uses the canvas width and height to "fill" the canvas and as a result also "clips" the ends of the tiles if they do not add up to the canvas width.. see pic above

there is no reason why the canvas could not be MUCH larger.

and using similar code scale the "fill" to fill-in ny section of the canvas you wanted at whatever you want it to be.

tiled_regions2.jpg


the following script draws a panel of exactly 3 wallpaper tiles wide by 4 wallpaper tiles deep starting at an offset from a "large" canvas of 100pixels in x-wise and 100pixels in y-wise from the canvas top right corner.

you could of course change the script slightly so that the "wallpaper" is always centered on the canvas.

Code: Select all
int i,j;

int wide=wallpaper.width*3;
int high=wallpaper.height*4;
int start_x=100;
int start_y=100;

for (i=0;i<wide;i=i+wallpaper.width)
{
  for (j=0;j<high;j=j+wallpaper.height)
  {
  draw_from("wallpaper",start_x+wallpaper.width/2+i,start_y+wallpaper.height/2+j, 1);
  }
}



feral