h2d.Object.move doesn't work as expected

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
        pos = new Object(s2d);
    override function update(dt:Float)
        var x:Float = 0;
        var y:Float = 0;
        if (Key.isDown(Key.UP))
        else if (Key.isDown(Key.DOWN))
        if (Key.isDown(Key.LEFT))
        else if (Key.isDown(Key.RIGHT))
        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();

As you can read in the API Documentation

move(dx:Float, dy:Float):Void
Move the object by the specified amount along its current direction (Object.rotation angle).

The move() function moves it along it’s current direction based on the ‘rotation’.

As we can see in the same documentation, the default setting for rotation is 0.

rotation:Float = 0
The rotation angle of this object, in radians.

Lastly, if we take a closer look at the implementation of the ‘move’ function on Github we see the following code:

Move the object by the specified amount along its current direction (Object.rotation angle).
public function move( dx : Float, dy : Float ) {
x += dx * Math.cos(rotation);
y += dy * Math.sin(rotation);

In your case, as by default the Object class has a 0 value for rotation, the value for Math.sin(rotation) is equal to sin(0) which is 0.

Performing a dy * 0 = 0, your y value is still 0, so so therefor y += 0 or 0 += 0 which is 0 and thus your Object is not moving along the y axis.

Change the value of rotation by Object.rotate(value) and you’ll see your y value changing.

Good luck! :slight_smile: