我检查了你的参考游戏,明白你所说的“2.5D”是什么意思。据我了解,解决此问题的最佳方法是通过转换对象的 x,y 坐标来创建伪三维。您将拥有一个为您进行转换的函数,这是我对示例的最佳猜测。
// This function takes in a x- and y-coordinates of an object corner and returns the
// coordinates of the corresponding back corner of an object.
var transform = function(x,y) {
// The farther the character is from the object, the more skew there would be.
// Here "char" is your globally recognized game character. If it was not in the scope
// of the function you'd have to pass it as a parameter.
var skew = (char.x > x) ? (char.x - x) : (x - char.x);
var newx = (skew * 0.1); // obviously this would be variable depending on your liking
// If the object corner is not on the ground (y == 0) then subtract from it's value,
// otherwise add.
var newy = (y > 0) ? (y - 10) : (y + 10);
};
在我的示例10
中,是更改 y 坐标的距离单位数量。这就是您的示例游戏的表现方式。希望我的意见有帮助
里根