alright, so i am working on a scrolling tilebased map, and i am having trouble removing old tiles. it keeps giving me dumb errors, or it removes a weird amount, then gives a dumb error.
btw,
new Container is an empty MC.
and New Tile is a 50x50 square.
var a = 0;
var b = 0;
var i = 0;
var sOffx:int;
var sOffy:int;
var speed = 5;
var xVel:int = speed;
var yVel:int = speed;
var ablit = 10;
var bblit = 13;
var cont = new Container;
cont.y = -50;
stage.addChild(cont);
stage.addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown);
var keyArray:Array = new Array();
for (i=0; i<222; i++) {
keyArray.push([i,false]);
}
var tName = [];
var curmap = [];
var mainmap = [
[1,0,0,1,0,0,1,1,0,0,1],
[0,1,1,0,1,1,0,0,1,1,0],
[1,0,0,1,0,0,1,1,0,0,1],
[0,1,1,0,1,1,0,0,1,1,0],
[1,0,0,1,0,0,1,1,0,0,1],
[0,1,1,0,1,1,0,0,1,1,0],
[1,0,0,1,0,0,1,1,0,0,1],
[0,1,1,0,1,1,0,0,1,1,0],
[1,0,0,1,0,0,1,1,0,0,1],
[0,1,1,0,1,1,0,0,1,1,0],
[1,0,0,1,0,0,1,1,0,0,1],
[0,1,1,0,1,1,0,0,1,1,0]
];
for (a=0; a<ablit; a++) {
curmap.push(mainmap[a]);
for (b=0; b<bblit; b++) {
if (mainmap[a]** == 1) {
var v = new Tile;
v.x = b*50;
v.y = a*50;
tName.push(v);
}
cont.addChild(v);
}
}
function chop() {
var l=0;
for (a=0; a<curmap[0].length; a++) {
if (curmap[a][0] == 1) {
cont.removeChild(tName[l]);
tName[l] = null;
tName.splice(l, 1);
l++;
}
}
}
function loop(event:Event) {
if (keyisdown(38)) {
sOffy -= speed;
}
if (keyisdown(40)) {
sOffy += speed;
}
if (sOffy < -51) {
chop();
sOffy+=50;
}
cont.y=sOffy;
}
function checkKeysDown(event:KeyboardEvent):void {
keyArray[event.keyCode][1]=true;
}
function checkKeysUp(event:KeyboardEvent):void {
keyArray[event.keyCode][1]=false;
}
function keyisdown(X) {
return keyArray[x][1];
}
can someone help prevent the errors?