Tiled Background In AS3
I've been transitioning to AS3 and am looking for just a simple solution to tile a 8px x 8px movie clip across the stage.I came across this post from a while back but doesn't seem to work the same when using in a class file. When I change the linkage properties, I'm unable to only put in a Class name because it's asking for a base class.http://www.kirupa.com/forum/showthre...nd#post2030073Any help would be awesome.Thanks!
KirupaForum > Flash > ActionScript 3.0
Posted on: 06-29-2008, 05:13 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Tiled Background
I have a little question about tiled backgrounds.
Say I have a 40x40px tileable background, that i want to tile all over the scene (note that it is a fullscreen flash-movie, in which the background is supposed to cover the entire window no matter how big it is).
I found a code-snippet which loops out the tiles in movieclips onto the _root.
My question is, is there any way to have the entire tile in a single movieclip so that i can control it?
What i'm going to do is have two separate background tiles, and when you switch between two different pages in the movie, the backgroundtile is supposed to fade into the other one.
http://www.strainworks.com/test/flash-stretch/test.html
There's a little demonstration of what i want to do, but with a 2 tiled images for background instead.
Tiled BackGround In As3
how do you do it?
i've got a book about Embedding bitmaps & loading Bitmaps, but these are the only 2 demos in the book i cant get working....
i've used the following code to loader a Bg called tile.png, but at a lost to explain how to tile the screen with it from here...
code: package {
import flash.display.Sprite;
import flash.display.Loader;
import flash.net.URLRequest;
public class LoadAsset extends Sprite {
public function LoadAsset() {
init();
}
private function init():void {
var loader:Loader = new Loader();
addChild(loader);
loader.load(new URLRequest("tile.png"));
}
}
}
i did think about creating a sprite the size of the screen and filling it with the loaded png tile - how would i do that?
i would also like to be able to call the tile from the library but cant get that code to work either - anyone help me out?
Tiled Background
My background loads on top of everything, no matter where I seem to put the script in the timeline.
Quote:
var tile:Sprite = new Sprite();
function tileBG(event:Event=null):void
{
tile.graphics.beginBitmapFill(new Pattern1(0, 0));
tile.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
tile.graphics.endFill();
addChild(tile);
}
tileBG();
what am I missing?
Tiled Background
ello!
Here's my thing: I'm to tile a 80x60 pixel image into a background mosaic using AS.
Here's the code:
ActionScript Code:
function fTiles():Void {
// height and width of the linked image
var nTileHeight:Number = 60;
var nTileWidth:Number = 80;
// how many times to cast the image along each axis
var nYaxis:Number = Math.round((Stage.height/nTileHeight)+1);
var nXaxis:Number = Math.round((Stage.width/nTileWidth)+1);
// for each colum attach image in rows
for(Y=0; Y<nYaxis; Y++) {
for (X=0; X<nXaxis; X++) {
var sCurrentX:String = X.toString(); //for dynamic naming purposes
var sCurrentY:String = Y.toString();
this.attachMovie("Tile", "mcTile"+sCurrentY+sCurrentX, this.getNextHighestDepth());
this["mcTile"+sCurrentY+sCurrentX]._x=nTileWidth*X;
this["mcTile"+sCurrentY+sCurrentX]._y=nTileHeight*Y;
}
}
}
and here's the problem: /edit: link removed, dead host
for some error in logics the image fails to cast if Y=1 and X>10 and I don't see it. needless to say it's killing me
Do you see the trouble? help!
Tiled Background
Hi,
There is a code for bitmap, how to rewrite code for movieClip:
Stage.scaleMode = "noScale";
Stage.align = "";
import flash.display.BitmapData;
var pattern:BitmapData = BitmapData.loadBitmap("bitmapname");
Stage.addListener(BGTile);
BGTile.onResize = createTiles;
function createTiles():Void {
with (_level0) {
beginBitmapFill(pattern);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
}
createTiles();
stop();
Tiled Background?
I am following the tutorial here: http://www.kirupa.com/developer/mx20...background.htm
And all that happens is I get one copy of my image in the bottom right corner, not tiled. I have copied the code exactly. Is there a problem with the code?
Can someone show me how to create a tiled background image? Thanks.
Edit: Using Flash MX, complete Noobie...
How Do I Put A Tiled Picture For A Background?
Instead of just a regular color for my background, I want a bitmap to be tiled across the background, how can I do that? If I add it to the background of my website, it's actually smaller than the larger background area, and just covers the back of the website area thats not as big as the whole screen.
Tiled Html Background
i've been viewing some of the forums regarding this subject, but i must be having a brain fart or something....i've been entering this code in the HTML bit...
<body bgcolor="#000000" background="cover/the_image.gif">
except i haven't used the cover bit because i was under the impression that i should put the name of the folder that the .gif is in.. ie.
<body bgcolor="#000000" background="what_ever_folder/bg.gif">
i just end up getiing the first color specified in the code..ie #000000
i've tried using using other extensions and i'm reaching a dead end...seems like such an easy task...
anyone know?
:confused
Resize Tiled Background?
I did the following and put it inside a listner hoping that it would retile the background when ever the stage (browser window) gets resized. However, it doesn't resize after it is initially drawn. Anyone got any ideas? thanks.
PHP Code:
import flash.display.BitmapData;
var pattern:BitmapData = BitmapData.loadBitmap("flowerPattern");
Stage.addListener(BGTile);
BGTile.onResize = createTiles;
function createTiles():Void {
with (_level0) {
beginBitmapFill(pattern);
moveTo(0, 0);
lineTo(Stage.width, 0);
lineTo(Stage.width, Stage.height);
lineTo(0, Stage.height);
lineTo(0, 0);
endFill();
}
}
createTiles();
Lining Up A SWF With A Tiled Background
I am curious if anyone can help me with a small problem I'm having. I recently decided I want to design a site with a very specific tiled background. Now the problem with this I can't seem to think of how to make sure my SWF lines up with the tiled background for different resolutions. Basically the SWF is going to be centered on the page and is going to incorporate the background so it needs to line up exactly with it (the first frame of the SWF basically will make it look like there is no SWF but just a full tiled background). I would presume people have encountered this problem before but I can't seem to come up with a solution. Anyways, thanks in advance for any help,
ChaseNYC
Tiled Background Question
I found some code online and it works fine. There's a bit of code that can be taken out and it still works. I just wanted to know why it's there.
Both examples below
//stage align/scale stuff
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//listen to see if the stage is resized
stage.addEventListener(Event.RESIZE, tileBG);
//create a sprite(movieclip without a timeline) called tile
var tile:Sprite;
//function to populate tiled bg onload and onResize
function tileBG(event:Event=null):void {
//create a reference to the old tile container
var oldTile:Sprite = tile;
//create a new tile container
tile = new Sprite();
//fill the container
tile.graphics.beginBitmapFill(new pattern(0, 0));
tile.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
tile.graphics.endFill();
//add the tile container to the display list
addChild(tile);
//get rid of the old container
if (oldTile != null && oldTile != tile) {
removeChild(oldTile);
}
}
tileBG();
Anyone share some light.
Thanks
Tiled Background Class
I'm trying to write a class for background tiling. But I get an error 1136: Incorrect number of arguments. Expected 1. On the last line imageLoaded() in private function res() to be exact, but I don't know of any arguments to give. What am I overlooking?
ActionScript Code:
public class Background extends Sprite{
private var cont:Sprite = new Sprite(); // Making a new Sprite to contain the bg
private var graph:Graphics = cont.graphics; // Setting the graphics of the Sprite
private var gradType:String = GradientType.RADIAL; // Setting the gradient type
private var colors:Array = [0x000000 , 0x000000]; // Setting the collors of the gradient
private var alphas:Array = [0 , .8]; // Setting the alpha's of the gradient
private var ratios:Array = [0 , 255]; // Setting the ratio of the gradient
private var matrix:Matrix = new Matrix(); // Making a new matrix for the gradient
private var spread:String = SpreadMethod.PAD;
public function Background():void
{
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(new URLRequest("bg/bg1.jpg"));
stage.align = StageAlign.TOP_LEFT; // Setting the stage align
stage.scaleMode = StageScaleMode.NO_SCALE; // Setting the stage scale mode
stage.addEventListener(Event.RESIZE , res); // Ading an event listener for resizing
}
private function imageLoaded(event:Event):void
{
matrix.createGradientBox(stage.stageWidth , stage.stageHeight);
// drawing
with(graph)
{
var image:BitmapData = new BitmapData(event.target.content.width, event.target.content.height);
image.draw(event.target.content);
trace (image)
beginBitmapFill(image);
lineStyle(1 , 0x000000 , 0);
drawRect(0 , 0 , stage.stageWidth , stage.stageHeight);
endFill();
graph.beginGradientFill(gradType , colors , alphas , ratios , matrix , spread);
drawRect(0 , 0 , stage.stageWidth , stage.stageHeight);
}
addChildAt(cont , 0); // Ading the background to the display list
}
private function res():void
{
imageLoaded(); // Redrawing the graphics// <<<<ERROR IS OCCURING HERE
}
}
}
Re: Centering A Tiled Background
If someone can help me with this problem. I want to centre a tiled background that is an exact fit and adjustable to every screen size. I want the background to not only centre in swf movie, but in the screen and browsers as well. Another thing, how do you embed an image or tiled background in the html of the swf file?
Preloading Tiled Background
I'm trying to complete tutorials on gotoandlearn.com but the fullbrowser backgrounds and the preloader clash. The instructions say to import the tiled graphic on the first frame but that obviously takes a while to load and cancels out the preloader. Unfortunately I can't just plunk the background into a layer. Is there a action script that will load the graphic without placing it on stage? I assume you can use attachMovie but that seems clunky. Any suggestions?
Code:
import flash.display.BitmapData;
container._x = Stage.width/2;
container._y = Stage.height/2;
var tile:BitmapData = BitmapData.loadBitmap("tile");
function fillBG() {
this.beginBitmapFill(tile);
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,685);
this.lineTo(0,685);
this.lineTo(0,0);
this.endFill();
}
fillBG();
Tiled Background Tutorial
Hi guys,
Great tutorial on http://www.kirupa.com/developer/flas...und_flash8.htm
How do you make it update to always fill whatever size the movie is dragged to?
AS2 - Swapping Out Tiled Background?
I have a tiled background in flash that resizes to fit the browser dimensions.
Here's the actionscript for it:
--
import flash.display.BitmapData;
logo._x = Stage.width / 2;
logo._y = Stage.height / 2;
var tile:BitmapData = BitmapData.loadBitmap("bg1");
function fillBG() {
this.beginBitmapFill(tile);
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.height);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}
fillBG();
var stageL:Object = new Object();
stageL.onResize = function() {
fillBG();
logo._x = Stage.width / 2;
logo._y = Stage.height / 2;
}
Stage.addListener(stageL);
--
Would it be possible to swap out the tiled background with a new tiled background when a user activates a button? I have 5 sections (photography, web design, graphic design, sketches, and about me) for each section I would like the background to swap out with a different tile image.
Tiled Background In Full Screen
I have a standalone player with 640x480 stage size and has:
fscommand("allowscale", "false");
fscommand("fullscreen", "true");
script on it.
It is possible to have a tiled image background outside the 640x480 instead of just plain color on it?
Any idea?
Nesting Dynamic MC For Tiled Background
Dear users:
I am trying to create a tiled background which incorporates some nesting. I have a function which creates a hexagon:
Code:
function makeHex2(holder_mc){
for(i=0;i<6;i++){
tempMovie=_root.holder_mc.attachMovie("line","line_"+i+"_mc",i);
tempMovie._rotation=i*60;
if (i==1){
tempMovie._x=50*i;
tempMovie.attachMovie("number_1_mc","n1_mc",i);
}
if (i==2){
tempMovie._x=50*(i-1)+(Math.cos(60/180*(Math.PI))*50);
tempMovie._y=(Math.sin(60/180*(Math.PI))*50)*(i-1);
}
if (i==3){
tempMovie._x=50*(i-2);
tempMovie._y=(Math.sin(60/180*(Math.PI))*50)*(i-1);
trace (tempMovie._y);
}
if (i==4){
tempMovie._x=-(Math.cos(60/180*(Math.PI))*50)*(i-4);
tempMovie._y=(Math.sin(60/180*(Math.PI))*50)*(i-2);
}
if (i==5){
tempMovie._x=-(Math.cos(60/180*(Math.PI))*50)*(i-4);
tempMovie._y=(Math.sin(60/180*(Math.PI))*50)*(i-4);
}
}
}
But when I try to load the function...
Code:
_root.onLoad=function(){
for (e=1;e<4;e++){
makeHex2("holder_"+e+"_mc");
holder_1_mc._x=100;
holder_2_mc._x=200;
holder_3_mc._x=400;
holder_4_mc._x=500;
}
}
... I come up with nothing.
I can create the hexagon with a simple _root.onLoad=function() handler, but how am I supposed to create the hexagon inside a nested "for" loop where I've created a grid of place-holder MovieClips?
Any help is greatly appreciated.
Button Over Tiled Background Image?
Good Day.
I have created a tiled background using the following script:
tileBG = function () {
tile_width = 34;
tile_height = 34;
//
x_max = Math.round(Stage.width/tile_width);
y_max = Math.round(Stage.height/tile_height);
trace(x_max);
trace(y_max);
for (x=0; x<=x_max; x++) {
for (y=0; y<=y_max; y++) {
bg = _root.attachMovie("square", "bg"+x+y, this.getNextHighestDepth());
bg._x = tile_width*x;
bg._y = tile_height*y;
}
}
};
tileBG();
Next, I created a layer named 'button' and imported an image to the stage. And when I test the movieclip, the button doesn't appear on the screen. Why is this so?
Tq.
Help Needed: Tiled Background 4 Scalable MC ?
Hello everyone, i got movieclip which i need to put repeating texture on, but the problem is that MC is scaling dynamically whenever stages scales to keep right proportions, so each time it scales texture scales with it and stretches...
Is it possible to fix texture on scalable MC?
Appreciate your help !
thanks
Full Screen + Tiled Background
I was doing the Kirupa full screen Flash page and tiled background tutorials, but was wondering how to combine the two. Individually they work great, but when I publish an HTML page with a full screen SWF, the background image isn't full screen--it only gets scaled correctly to the right.
Any ideas / suggestions / tutorials? Thanks!
Resizing Tiled Background In Flash 8
Hello,
I've checked out this tutorial, and it's great:
http://www.kirupa.com/developer/flas...und_flash8.htm
But, is there a way, to make the background scale, when you resize the movie. I made this AS code:
Code:
import flash.display.BitmapData;
var tile:BitmapData = BitmapData.loadBitmap("pattern");
this.beginBitmapFill(tile);
this.lineTo(Stage.width, 0);
this.lineTo(Stage.width, Stage.height);
this.lineTo(0, Stage.height);
this.lineTo(0, 0);
this.endFill();
//-----------------------
sizeListener = new Object();
sizeListener.onResize = function() {
var tile:BitmapData = BitmapData.loadBitmap("pattern");
this.beginBitmapFill(tile);
this.lineTo(Stage.width, 0);
this.lineTo(Stage.width, Stage.height);
this.lineTo(0, Stage.height);
this.lineTo(0, 0);
this.endFill();
};
Stage.addListener(sizeListener);
But it doesn't work... I'm confused, what should I do?..
Problem With Tiled Background. Urgent Help Please
Hi guys!
I'm trying to tile the background of a movieClip with a set of small squares, called grid. However, the script only attaches on instance of grid. I don't understand why this is. Below is my code exert:
ActionScript Code:
function tileGrid() { grid_width = 20; grid_height = 20; // x_max = Math.round(canvas_mc._width/grid_width); y_max = Math.round(canvas_mc._height/grid_height); for (x=0; x<x_max; x++) { for (y=0; y<y_max; y++) { bg = this.canvas_mc.attachMovie("grid", "gd"+x+y, 100+x*y); bg.duplicateMovieClip({_x: grid_width*x, _y: grid_width*y}); }// End of inner loop }// End of outer loop}tileGrid();
If anybody could explain a reason for this, or remedy my code, I would be very grateful.
Many thanks
TAJ
P.S. Please find attached a copy of the source.
Tiled Background In AS3, Help To Modify A Function.
Hello you all.
Ok i'm new here and really new to AS3, i was beginning to understand AS2 (lol) and now I have to compile this working AS2 function to AS3, can you help me and comment it so that I can understand. Many many thanks.
(ps. can you maybe give me the url of a website where I can look for simple commented AS3 to learn again cause I'm lost with all these removed and new functions)
Thhis script is to tile a file loaded in the Library and called 'pattern' all over the stage.
Code:
import flash.display.BitmapData;
var tile:BitmapData = BitmapData.loadBitmap("pattern");
this.beginBitmapFill(tile);
this.lineTo(Stage.width, 0);
this.lineTo(Stage.width, Stage.height);
this.lineTo(0, Stage.height);
this.lineTo(0, 0);
this.endFill();
Changing Tiled Background W/ Buttons
hello,
I used the full browser flash tut. to make a tiles background in my site, but I like my siteuser to be able to change the background.
Therefore I tried the following code:
Code:
import flash.display.BitmapData;
var tile:BitmapData = BitmapData.loadBitmap("tile1");
this.background.BA1.onRelease = function() {
tile = BitmapData.loadBitmap("tile1");
fillBG();
function fillBG() {
this.beginBitmapFill(tile);
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.width);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}
fillBG();
wich is the extension of the tutorials code, with button BA1 should change the background til to "tile1"
I already checked the linkage and names of the buttons..
can anyone tell me what I'm doing wrong?
thanks,
[CS3] Unscaled Tiled Background With Scaling MC Overlay
Attempting to recreate an effect I've seen elsewhere, using an SWF to handle all scaling with an unscaled tiled background and gradient overlay that scales with the SWF/browser.
I've been able to pull together the two ideas from research around these forums/the web, but am stuck now. I'm able to get the background to work perfectly, and the overlay to scale correctly upon opening, but can't seem to add (what I believe to be) a listener to dynamically scale and rescale the overlay. My code is below:
Quote:
//background//
Stage.scaleMode = "noScale";
Stage.align = "TL";
import flash.display.BitmapData;
var tile:BitmapData = BitmapData.loadBitmap("tile");
function fillBG() {
_root.backGround_mc.beginBitmapFill(tile);
this.backGround.moveTo(0, 0);
this.backGround_mc.lineTo(Stage.width, 0);
this.backGround_mc.lineTo(Stage.width, 4000);
this.backGround_mc.lineTo(0, 4000);
this.backGround_mc.lineTo(0, 0);
this.backGround_mc.endFill();
}
fillBG();
//initial position//
backGround_mc._y = Stage.height/2-backGround_mc._height/2;
//background listener//
var myListener:Object = new Object();
myListener.onResize = function() {
backGround_mc._y = Stage.height/2-backGround_mc._height/2;
fillBG();
};
Stage.addListener(myListener);
//gradient overlay//
gradient._width = Stage.width;
gradient._height = Stage.height;
I know the code is a little funky, as well. I'm not an expert (I'm an artist first, more of a debugger/fixer than coder last) and would appreciate any advice to slim/correct what I have. The big issue is getting that silly gradient MC to scale dynamically.
Thank you!
Creating A Tiled Background Flash File
I purchased a basic flash XML template and have customised all content and pages to suit as necerssary however the background is a tiled bitmap file, which is great as it resizes to any resolution without pixelating.
I have Adobe Flash CS3 trial, how do I change the bitmap file to that of my own? I cannot see how..
Please find attached FLA/SWF & Bitmap file
Dynamically Loaded JPEG For Tiled Background?
Is it possible to dynamically load a JPEG image and use it as a tiled background for a fullscreen flash movie?
Everything I see online is for bitmaps already loaded in the library.
I don't see why it wouldn't be possible.
Thanks!
Full Screen Tiled Background Question...
I love the tutorial on how to make a tiled background in Flash.
I was wondering if anyone knows how to change the tiled background to something different. The scenario for example is each section of the site the background has the same tiled background but just different colors.
I've made all 4 different tiled background now all I need to do is make them switch out when a link/button is triggered.
Anyone see this done before and can direct me to a tutorial or willing to help me out
thanks!
Tiled Background Inside A Movieclip (full Page)
I’m no flash guru or anywhere near it but I though I’d post this as it might be helpful to someone, the code is from the gotoandlearn tutorial on tiled backgrounds, I’ve just had a play with it to suit something I’m working on.
I’m sure someone could clean it up though.
How To Transform A Tiled Map ?
Salut !!
I need help, cause I'm lost !
I study how to make my own tiles based game, and I understand most of the sources posted here. But I'm desesperatly trying to create my own engine for an iso map.
Can you help me, where can I find some sources or tutorials about creating iso-tiles based games ?
I post here my code, because it may be just a little thing to change. Here it is :
---------------------------------------------------------------
// our map is 2-dimensional array
myMap = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 1, 0, 1], [1, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1]];
// declare game object that holds info
game = {tileW:30, tileH:30};
// walkable tile
game.Tile0 = function () { };
game.Tile0.prototype.walkable = true;
game.Tile0.prototype.frame = 1;
// wall tile
game.Tile1 = function () { };
game.Tile1.prototype.walkable = false;
game.Tile1.prototype.frame = 2;
// declare char object, xtile and ytile are tile where chars center is
char = {xtile:2, ytile:1, speed:4};
// building the world
function buildMap(map) {
// attach empty mc to hold all the tiles and char
_root.attachMovie("empty", "tiles", 1);
// declare clip in the game object
game.clip = _root.tiles;
// get map dimensions
var mapWidth = map[0].length;
var mapHeight = map.length;
// loop to place tiles on stage
for (var i = 0; i<mapHeight; ++i) {
for (var j = 0; j<mapWidth; ++j) {
// name of new tile
var name = "t_"+i+"_"+j;
// make new tile object in the game
game[name] = new game["Tile"+map[i][j]]();
// attach tile mc and place it
game.clip.attachMovie("tile", name, i*100+j*2);
game.clip[name]._x = (j*game.tileW);
game.clip[name]._y = (i*game.tileH);
// send tile mc to correct frame
game.clip[name].gotoAndStop(game[name].frame);
}
}
// add the character mc
game.clip.attachMovie("char", "char", 10000);
// declare clip in the game object
char.clip = game.clip.char;
// calculate starting position
char.x = (char.xtile*game.tileW)+game.tileW/2;
char.y = (char.ytile*game.tileW)+game.tileW/2;
// add char dimensions to char object, half of clips width and height
char.width = char.clip._width/2;
char.height = char.clip._height/2;
// place char mc
char.clip._x = char.x;
char.clip._y = char.y;
}
function getMyCorners(x, y, ob) {
// find corner points
ob.downY = Math.floor((y+ob.height-1)/game.tileH);
ob.upY = Math.floor((y-ob.height)/game.tileH);
ob.leftX = Math.floor((x-ob.width)/game.tileW);
ob.rightX = Math.floor((x+ob.width-1)/game.tileW);
// check if they are walls
ob.upleft = game["t_"+ob.upY+"_"+ob.leftX].walkable;
ob.downleft = game["t_"+ob.downY+"_"+ob.leftX].walkable;
ob.upright = game["t_"+ob.upY+"_"+ob.rightX].walkable;
ob.downright = game["t_"+ob.downY+"_"+ob.rightX].walkable;
}
function moveChar(ob, dirx, diry) {
// vertical movement
// where are our edges?
// first we look for y movement, so x is old
getMyCorners(ob.x, ob.y+ob.speed*diry, ob);
// move got dammit... and check for collisions.
// going up
if (diry == -1) {
if (ob.upleft and ob.upright) {
// no wall in the way, move on
ob.y += ob.speed*diry;
} else {
// hit the wall, place char near the wall
ob.y = ob.ytile*game.tileH+ob.height;
}
}
// if going down
if (diry == 1) {
if (ob.downleft and ob.downright) {
ob.y += ob.speed*diry;
} else {
ob.y = (ob.ytile+1)*game.tileH-ob.height;
}
}
// horisontal movement
// changing x with speed and taking old y
getMyCorners(ob.x+ob.speed*dirx, ob.y, ob);
// if going left
if (dirx == -1) {
if (ob.downleft and ob.upleft) {
ob.x += ob.speed*dirx;
} else {
ob.x = ob.xtile*game.tileW+ob.width;
}
}
// if going right
if (dirx == 1) {
if (ob.upright and ob.downright) {
ob.x += ob.speed*dirx;
} else {
ob.x = (ob.xtile+1)*game.tileW-ob.width;
}
}
// update char position
ob.clip._x = ob.x;
ob.clip._y = ob.y;
// face the direction
ob.clip.gotoAndStop(dirx+diry*2+3);
// calculate the tile where chars center is
ob.xtile = Math.floor(ob.clip._x/game.tileW);
ob.ytile = Math.floor(ob.clip._y/game.tileH);
return (true);
}
function detectKeys() {
var ob = _root.char;
var keyPressed = false;
if (Key.isDown(Key.RIGHT)) {
keyPressed = _root.moveChar(ob, 1, 0);
} else if (Key.isDown(Key.LEFT)) {
keyPressed = _root.moveChar(ob, -1, 0);
} else if (Key.isDown(Key.UP)) {
keyPressed = _root.moveChar(ob, 0, -1);
} else if (Key.isDown(Key.DOWN)) {
keyPressed = _root.moveChar(ob, 0, 1);
}
// walk animation
if (!keyPressed) {
ob.clip.char.gotoAndStop(1);
} else {
ob.clip.char.play();
}
}
// make the map
buildMap(myMap);
stop();
------------------------------------------------------------------
Thanx a lot !!!!
Tiled Backgrounds
http://www.sharifatkins.com/
The background on that site tiles, is this done with action script or is there another way to tile backgrounds with flash? thanks for your help.
Tiled Backgrounds
http://www.sharifatkins.com/
The background on that site tiles, is this done with action script or is there another way to tile backgrounds with flash? thanks for your help.
Dynamically Tiled BG
any ideas?
Here is what I am debating. I was going to go with the whole full screen flash movie. However, I nneded to tile a background. I have read a lot about getting the background to tile properly, however, this dosent seem to work if I am going to scale the bg object to the size of the browser window. So, the next idea I had, was to do a transparent flash bg, and just let html dynamically repeat the background. But I dont know much about the transparent background. It seems to have good browser compatability, but I'm just afraid of prossessing speeds. Will the transparency do anything weird to motion tweens, and any other kind of tweening?
Or are there any other ideas to get a background to tile dynamacally?
Thanks
Getting A Tiled Image To Appear Above Others. (MX2004)
Sorry I forgot to press MX2004
Hi,
I have developed the attached site as a practise exercise. It basically consists of a wall of tiled identical images.
What I would like to have happen is, as a user rolls over an image it’s _xscale & _yscale go up to 150 & (the bit I’m having the problems with) it appears above all the other images on the wall.
I am really at a loss as to how to achieve this & would be grateful for any help.
A slightly amended script as it currently stands is set out below & the fla is attached.
code:
depth = 100;
for (i=0; i<5; ++i) {
for (j=0; j<10; ++j) {
this.wall_mc.attachMovie("cat", "cat"+depth, ++depth);
thisCat = _root.wall_mc["cat"+depth];
thisCat.onRollOver = function() {
my_sound.start();
this._xscale = this._yscale=150;
};
thisCat.onRollOut = function() {
this._xscale = this._yscale=100;
};
thisCat._x = 40*j;
thisCat._y = 40*i;
}
Tiled Map Problem, Need Better Script
I generate tiles in a square based on an array. The tiles are named tile0, tile1, tile2, etc. I need to only display the tiles seen on screen. If a tile is not on screen, it needs to be invisible. This will help CPU usage.
I have this code:
ActionScript Code:
//ttc is the Total Tile Count for the map array you load.
function hide(ttc){
for(i=0; i<ttc; i++){
if (land["tile" + i]._y < _root.topbound || land["tile" + i]._y > _root.bottombound || land["tile" + i]._x < _root.leftbound || land["tile" + i]._x > _root.rightbound) {land["tile" + i]._visible = 0;}
else {land["tile" + i]._visible = 1;}
}
}
and it works very well for small maps like 5tilesx5tiles however it slows the CPU down emensly when I do 40x40. This is because it has to run that code 1600 times every frame because there are 1600 different tiles with a 40x40 map. I need a script that will do the same effect, only faster.
I have tried sticking an IF statement in there with a condition that would only make the script execute once a second, however that still gives me a slight lag. I thought about distributing the tiles between several FOR loops then running one at a time every second, but that seems too drawn out. I honestly can't think of any other way to do this. :-
Any help would be greatly appreciated.
Duplicate (Tiled) Backgrounds
http://www.kirupa.com/developer/mx20...background.htm
from this tutorials, instead of duplicating both X and Y planes, I want it to only duplicate X
for example, http://nano3.org
you can see the grey fading into white, I just want the fade in my flash which is already an image.
thanks
Help With Scaling And Borders With A Tiled Bg
i hope some one can help i created a flash document and then added a tiled background to the atage using this code
import flash.display.BitmapData;
var tile:BitmapData = BitmapData.loadBitmap("kpattern2");
this.beginBitmapFill(tile);
this.lineTo(Stage.width, 0);
this.lineTo(Stage.width, Stage.height);
this.lineTo(0, Stage.height);
this.lineTo(0, 0);
this.endFill();
but i am unable to place a border around the stage and unable to place the satge in the centre of the page when viewed in the browser can anyone help please
Tiled Based Games In Flash MX
Hello people,
I'm currently working on my first tile based game. It's a zelda type game so I need the array map to be able to scroll up, down, left and right.
I have managed to get this working but I'm having problems adding and removing the tiles that are not in view.
Does anyone have the script or know where I can get it or explain to me how it works?
Cheers,
Ex-Ess
[F8] Non-tiled Isometric Swap Depth
Hi all,
so much has been written about swaping depths in iso world and yet more needs to be answered. My problem wouldn't exist if I used the classic tiled engine, but really, there is no way how I can insert it into my aplication.
On the picture below is what I'm trying to explain in words here:
Basicaly I am using rectangle objects of variable sizes and not only proportions but really different height and width values for each of them.
Now if you imagine a very long rectangle and a square, there is very likely a difficult situation to occur, when the small square should be in front of the long one, but acording to the algorytm it wouldn't.
Now I probably need to manage something with width and height of each object, but I feel a little lost here...if anyone could give me a hint, thx ya all
Using Tiled Images With A MovieClip In Front.
Hey, I've been following this tutorial http://www.kirupa.com/developer/mx20...background.htm to produce a tiled backdrop. But if I try to put anything in front of the tiled background it only gets sent to the back, meaning you will only ever see the tiled background regardless of where you place a movie clip.?
Tiled Bitmaps With Gaps When Zoomed
Hello, I'm making a tile based game, and it seems that there are visible gaps when it is zoomed. My tiles are pixel perfect 20x20 and they are all dynamically created by script. Does anyone know of a solution or can point me to a solution in the net? I've googled for this and failed to find a solution.
[F8] Blending Adjacent Tiled Movie Clips
Hello everyone,
Is there an easy effective way to use actionscript to blend the contents of two overlapping movie clips with some kind of transparency gradient so that it appears that one movie clip is fading right into the other one and vice versa? I want to be able to take my tiled movie clips in the same scene and cause the tiles to blend seamlessly into the adjacent tiles. The tiling process is dynamic so an actionscript solution would be so helpful!
Thanks!
David
Image Transparency Screws Up When Tiled Over 10+ Layers..
hello,
im trying to create mulitple images on top of one another to build an object using pixel graphics, therefore i need transparent images. problem is once i layer over 10 transparent png-24 or gif images, the 11th image causes the first image to be blocked out (as if the 11th image has a background over the first image). does anyone know what i am talking about?
is this a known issue with flash?
i have searched the forums and havent found anything talking about this..
please point me in the right direction if i missed it.
i am using flash mx 2004
thanks alot
Blending Adjacent Tiled Movie Clips
Hello everyone,
Is there an easy effective way to use actionscript to blend the contents of two overlapping movie clips with some kind of transparency gradient so that it appears that one movie clip is fading right into the other one and vice versa? I want to be able to take my tiled movie clips, which are in the same scene, and cause the tiles to blend seamlessly into the adjacent tiles. The tiling process is dynamic so an actionscript solution would be so helpful!
Thanks!
David
|