I’m making an isometric game (like Ultima VI), and I have some problems with layers. When the player approaches a wall from the right and the bottom he should be shown over the wall. Instead, he is not rendered over it until he stops. While the player is moving he always appears under the wall, but if he stops he is correctly rendered over it when he is on the bottom and on the right.
The wall has a 48x48 sprite and its base is 32x32, the player has 32x32 sprite and its base is 16x16.
This is the player:
public class Player extends Entity
{
[Embed(source="../lib/Player.png")]
private const MAN:Class;
private var spriteMap:Spritemap = new Spritemap(MAN, 32, 32);
private const unit:int = 32;
public var v:Point=new Point;
public function Player()
{
graphic = spriteMap;
graphic.x = graphic.y = -16;
spriteMap.add("Idle", [0]);
mask = new Hitbox(16,16,0,0);
type = "player";
spriteMap.play("Idle");
}
override public function update():void
{
upMovement();
upCollision();
layer = 16 - (x + y);
trace(layer);
}
public function upMovement():void
{
var move:Point = new Point;
if (Input.check(Key.RIGHT)) move.x++;
if (Input.check(Key.LEFT)) move.x--;
if (Input.check(Key.DOWN)) move.y++;
if (Input.check(Key.UP)) move.y--;
v.x = 150 * FP.elapsed * move.x;
v.y = 150 * FP.elapsed * move.y;
}
public function upCollision():void
{
x += v.x;
if (collide("wall", x, y))
{
if (FP.sign(v.x) > 0)
{
v.x = 0;
x = Math.floor(x / 32) * 32 + 16;
}
else
{
v.x = 0;
x = Math.floor(x / 32) * 32 + 32;
}
}
y += v.y;
if (collide("wall", x, y))
{
if (FP.sign(v.y) > 0)
{
v.y = 0;
y = Math.floor(y / 32) * 32 + 16;
}
else
{
v.y = 0;
y = Math.floor(y / 32) * 32 + 32;
}
}
}
}
And this is the world:
public class Tav1 extends World
{
[Embed(source="../lib/Wall.png")]
private const WALL:Class;
private const unit:int = 32;
private var wall:Image = new Image(WALL);
private var player:Player = new Player();
public function Tav1()
{
add(new Wall);
spawnwall(wall, 5, 5);
spawnwall(wall, 5, 6);
spawnwall(wall, 6, 5);
spawnwall(wall, 6, 6);
add(player);
}
public function spawnwall(img:Image, wx:int, wy:int):void
{
addGraphic(img, -(wx+wy) * unit, wx * unit-16, wy * unit-16);
}
}
I tried a lot of different things but nothing works. At this point the problem should probably be in the way I move the player or in flashpunk itself. I’m blocked, help me.