# Tile Help...I don't understand what I am doing wrong

**URL:** <https://forum.kirupa.com/t/tile-help-i-dont-understand-what-i-am-doing-wrong/222065>\
**Category:** flash\
**Created:** [April 10, 2007, 2:34pm UTC](https://forum.kirupa.com/t/tile-help-i-dont-understand-what-i-am-doing-wrong/222065 "2007-04-10T14:34:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregmax](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gregmax](https://forum.kirupa.com/u/gregmax)\
**Post date:** [April 10, 2007, 2:34pm UTC](https://forum.kirupa.com/t/tile-help-i-dont-understand-what-i-am-doing-wrong/222065/1 "2007-04-10T14:34:48Z")

</div>

I learning how to make worlds with the help of tiles and Tonypa. I am in the scrolling tutorial and I believe I am following everything but apparently not! For some reason it will not generate the surrounding tiles around the hero/char when it is moving (it works fine when it firsts builds the map, its the walking/scrolling part that doesn’t). Here it was I have:

(at the bottom of move char)  
game.clip.\_x = game.center\_x - obj.x;  
game.clip.\_y = game.center\_y - obj.y;  
if(obj.x\_step \< (obj.x - game.t\_size)) {  
var x\_tile = Math.floor(obj.x\_step / game.t\_size) + 1;  
var x\_new = x\_tile + int(game.visible\_x/2) + 1;  
var x\_old = x\_tile - int(game.visible\_x/2) - 1;  
for(var i = (obj.y\_tile - int(game.visible\_y/2)-1); i \< (obj.y\_tile + int(game.visible\_y/2)+1); i++) {  
change\_tile(x\_old, i, x\_new, i);  
}  
obj.x\_step += game.t\_size;  
} else if(obj.x\_step \> obj.x) {  
var x\_tile = Math.floor(obj.x\_step / game.t\_size);  
var x\_old = x\_tile + int(game.visible\_x/2) + 1;  
var x\_new = x\_tile - int(game.visible\_x/2) - 1;  
for(var i = (obj.y\_tile - int(game.visible\_y/2)-1); i \< (obj.y\_tile + int(game.visible\_y/2)+1); i++) {  
change\_tile(x\_old, i, x\_new, i);  
}  
obj.x\_step -= game.t\_size;  
}  
if(obj.y\_step \< (obj.y - game.t\_size)) {  
var y\_tile = Math.floor(obj.y\_step / game.t\_size) + 1;  
var y\_new = y\_tile + int(game.visible\_y/2) + 1;  
var y\_old = y\_tile - int(game.visible\_y/2) - 1;  
for(var i = (obj.x\_tile - int(game.visible\_x/2)-1); i \< (obj.x\_tile + int(game.visible\_x)+1); i++) {  
change\_tile(i, y\_old, i, y\_new);  
}  
obj.y\_step += game.t\_size;  
} else if(obj.y\_step \> obj.y) {  
var y\_tile = Math.floor(obj.y\_step / game.t\_size);  
var y\_old = y\_tile + int(game.visible\_y/2) + 1;  
var y\_new = y\_tile - int(game.visible\_y/2) - 1;  
for(var i = (obj.x\_tile - int(game.visible\_x/2)-1); i \< (obj.x\_tile + int(game.visible\_x)+1); i++) {  
change\_tile(i, y\_old, i, y\_new);  
}  
obj.y\_step -= game.t\_size;  
}

(and the change\_tile function)

function change\_tile(x\_old, y\_old, x\_new, y\_new) {

```
var old_nm = "t_" + y_old + "_" + x_old;
var new_nm = "t_" + y_new + "_" + x_new;

if(y_new &gt;= 0 and x_new &gt;= 0 and y_new &lt;= _root.walk.length-1 and x_new &lt;= _root.walk[0].length-1) {
	
	game[new_nm] = new game["walk_" + _root.walk[y_new][x_new]]();
	game.clip[old_nm]._name = new_nm;
	game.clip[new_nm].gotoAndStop(game[new_nm].frame);		
	game.clip[new_nm]._x = (x_new * game.t_size);
	game.clip[new_nm]._y = (y_new * game.t_size);
	
} else {

	game[new_nm] = new game.walk_2();
	game.clip[old_nm]._name = new_nm;
	game.clip[new_nm].gotoAndStop(game[new_nm].frame);
	
}

```

}

I appreciate any help given, thanks in advance!
