Behaviors in javascript code

How can I manipulate the behavior properties in the javascript code event?

For example I already got the behavior I want (“TopDownMovement”) and I checked the key presses, now how do i simulate the keystroke of this behavior?

const player = runtimeScene.getObjects('Player')[0];
const light = runtimeScene.getObjects('Light')[0];
const behaivor = player.getBehavior('TopDownMovement');
const keyboard = runtimeScene.getGame().getInputManager();

light.setX(player.getX());
light.setY(player.getY());

runtimeScene.setBackgroundColor(255,255,255);

if (keyboard.isKeyPressed(65)) {
    player.flipX(true);
} else if (keyboard.isKeyPressed(68)) {
    player.flipX(false);
}

if (keyboard.isKeyPressed(87)) {

} else if (keyboard.isKeyPressed(83)) {

}

On topdownmovement behavior, you can do:

  • ignoreDefaultControls(true)
  • simulateLeftKey
  • simulateRightKey
  • simulateUpKey
  • simulateDownKey
  • simulateControl(“Left”) //Left, Right, Up, Down

The js doc is not written yet, you can see the method here..

1 Like

Oh I’m sorry, I was putting the name of the method as simulateLeftKeyPress, so the correct name doesn’t have the “Press”

Thank you!