Forum Topic: AS Tiles Help!

(92 views • 7 replies)

This topic is 1 page long.

<< < > >>
None

Snubby

Reply To Post Reply & Quote

Posted at: 8/11/06 11:22 AM

Snubby FAB LEVEL 20

Sign-Up: 12/04/04

Posts: 3,145

I really hate to ask AS questions, but here ya go. I've got 'tile' in my library with 2 frames, to represent the different tiles (im making a tile engine).

I want to make a function to draw a 2-dimensional array that holds the tiles, yet WTF it doesn't work. The funny thing is I've gotten it to work many times before.

var myMap:Array = Array(
[1, 1, 1],
[1, 0, 1],
[1, 1, 1]
);
function buildMap(map)
{
for(ver = 0; ver < 3; ver ++)
{
for(hor = 0; hor < 3; hor ++)
{
_root.attachMovie("tile", "t_" + hor + "_" + ver, _root.getNextHighestDepth());
_root["t_" + hor + "_" + ver]._x = map[ver][hor] * 30;
_root["t_" + hor + "_" + ver]._y = map[ver] * 30;
_root["t_" + hor + "_" + ver].gotoAndStop(map[ver][hor] + 1);
}
}
}
buildMap(myMap);

This is what I am getting. I really need help here, guys.


None

Snubby

Reply To Post Reply & Quote

Posted at: 8/11/06 11:33 AM

Snubby FAB LEVEL 20

Sign-Up: 12/04/04

Posts: 3,145

I just realized that the _x and _y setting is the problem, for this works...

myMap = [[1, 1, 1],[1, 0, 1],[1, 1, 1]];
for(var ver = 0; ver < 3; ver ++)
{
for(var hor = 0; hor < 3; hor ++)
{
_root.attachMovie("tile", "t_" + hor + "_" + ver, _root.getNextHighestDepth());
_root["t_" + hor + "_" + ver].gotoAndStop(_root.myMap[ver][hor] + 1);
trace(myMap[ver][hor]);
}
}

So please take a look, whats wrong with these scripts?!

_root["t_" + hor + "_" + ver]._x = map[ver][hor] * 30;
_root["t_" + hor + "_" + ver]._y = map[ver] * 30;


None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 8/11/06 11:35 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

I may be really stupif for saying this, but its early, and im tried, so.

Shouldn't it be

var map:Array = new Array ([0,0,0],[1,0,1],[0,1,0]);

I dont know if you need the new in their or not. But im tired as hell, so meh.


None

Snubby

Reply To Post Reply & Quote

Posted at: 8/11/06 11:38 AM

Snubby FAB LEVEL 20

Sign-Up: 12/04/04

Posts: 3,145

At 8/11/06 11:35 AM, pyro111 wrote: I may be really stupif for saying this, but its early, and im tried, so.

Shouldn't it be

var map:Array = new Array ([0,0,0],[1,0,1],[0,1,0]);

I dont know if you need the new in their or not. But im tired as hell, so meh.

Nope sorry, you dont. Thanks for trying : )

Also, why is this returning NaN, NaN, NaN...

trace((myMap[hor] * 30));


None

Snubby

Reply To Post Reply & Quote

Posted at: 8/11/06 11:45 AM

Snubby FAB LEVEL 20

Sign-Up: 12/04/04

Posts: 3,145

I'm SO STUPID FOR MAKING THIS THREAD THE ANSWER WAS SO EASY! Please lock this thread for nobody to see!

var myMap:Array = new Array([1, 1, 1],[1, 0, 1],[1, 1, 1]);
for(j = 0; j < 3; j ++)
{
for(i = 0; i < 3; i ++)
{
attachMovie("tile", "t_" + i + "_" + j, _root.getNextHighestDepth());
_root["t_" + i + "_" + j]._x =i * 30;
_root["t_" + i + "_" + j]._y = j * 30;
_root["t_" + i + "_" + j].gotoAndStop(_root.myMap[j][i] + 1);
}
}

i was multiplying the array!! lol!


None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 8/11/06 11:48 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

// Here is a tile engin I used to create a brick game. Welsh Dragon helped me make it, but maybe you can look at it and it will help you. (This was made in API btw, so its gonna vary a bit)

var tileheight:Number = 20;
var tilewidth:Number = 30;
brickMap = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0], [0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0], [0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0], [0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0], [0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0], [0, 2, 2, 0, 0, 0, 0, 2, 1, 1, 2, 0, 0, 0, 0, 0, 2, 2, 0]];
brick = createBrick(0x01017E);
brick2 = createBrick(0x0000FF);
drawBricks();
function createBrick(color) {
z == undefined ? z=-1 : 0;
mc = this.createEmptyMovieClip("brick"+z, z--);
with (mc) {
lineStyle(1, 0x000000, 50);
beginFill(color, 100);
moveTo(0, 0);
lineTo(0, tileheight);
lineTo(tilewidth, tileheight);
lineTo(tilewidth, 0);
lineTo(0, 0);
endFill();
}
return mc;
}
function drawBricks() {
for (j=0; j<brickMap.length; j++) {
for (i=0; i<brickMap[0].length; i++) {
if (brickMap[j][i] == 1) {
pos = j*brickMap[0].length+i;
duplicateMovieClip("brick", "brick"+pos, this.getNextHighestDepth());
this["brick"+pos]._x = i*tilewidth;
this["brick"+pos]._y = j*tileheight;
}
if (brickMap[j][i] == 2) {
pos = j*brickMap[0].length+i;
duplicateMovieClip("brick2", "brick"+pos, this.getNextHighestDepth());
this["brick"+pos]._x = i*tilewidth;
this["brick"+pos]._y = j*tileheight;
}
}
}
brick.swapDepths(this.getNextHighestDepth(
));
brick.removeMovieClip();
brick2.swapDepths(this.getNextHighestDepth
());
brick2.removeMovieClip();
}


None

Pyromaniac

Reply To Post Reply & Quote

Posted at: 8/11/06 11:58 AM

Pyromaniac EVIL LEVEL 18

Sign-Up: 01/14/05

Posts: 2,968

Im sorry for the double post, but wouldnt this be better? More editable anyway. But you were probably going to change it to sometihng liek this after you finished the basic engin I guess.


tW = 50;
tH = 50;
var myMap:Array = new Array([0, 1, 0], [0, 0, 1], [0, 0, 0]);
for (j=0; j<myMap.length; j++) {
for (i=0; i<myMap[0].length; i++) {
attachMovie("tile", "t_"+i+"_"+j, _root.getNextHighestDepth());
_root["t_"+i+"_"+j]._x = i*tW;
_root["t_"+i+"_"+j]._y = j*tH;
_root["t_"+i+"_"+j].gotoAndStop(_root.myMa
p[j][i]+1);
_root["t_"+i+"_"+j]._width = tW;
_root["t_"+i+"_"+j]._height = tH;
}
}


None

Snubby

Reply To Post Reply & Quote

Posted at: 8/11/06 02:19 PM

Snubby FAB LEVEL 20

Sign-Up: 12/04/04

Posts: 3,145

At 8/11/06 11:58 AM, pyro111 wrote: Im sorry for the double post, but wouldnt this be better? More editable anyway. But you were probably going to change it to sometihng liek this after you finished the basic engin I guess.

i was just seeing if it would work i dont need to get fancy.


All times are Eastern Standard Time (GMT -5) | Current Time: 09:13 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!