I have a h2d.Object
(myObject) and can’t seem to be able to set it’s position using the Object.move()
function.
myObject.move(dx, dy); // Moves myObject by dx, but not by dy
wheras changing the public fields x
and y
:
myObject.x += dx; // Moves myObject by dx
myObject.y += dy; // Moves myObject by dy
works as expected.
I am new to heaps, and wonder whether I am missing something ?
Full code:
// In Main.hx
import h2d.Object;
import hxd.Key;
class Main extends hxd.App
{
var pos:Object;
override function init():Void
{
super.init();
pos = new Object(s2d);
}
override function update(dt:Float)
{
super.update(dt);
var x:Float = 0;
var y:Float = 0;
if (Key.isDown(Key.UP))
{
y++;
}
else if (Key.isDown(Key.DOWN))
{
y--;
}
if (Key.isDown(Key.LEFT))
{
x++;
}
else if (Key.isDown(Key.RIGHT))
{
x--;
}
pos.move(x*dt, y*dt);
// pos.x += x*dt;
// pos.y += y*dt;
if (hxd.Timer.frameCount >= 60)
{
hxd.Timer.frameCount = 0;
trace(pos.x, pos.y); // shows that x is changing, but y is not
}
}
static function main()
{
new Main();
}
}