Hey there,
I am relatively new to construct. To practice I want to try to write the Flappy Bird template project fully in JavaScript.
So first I created a Class Player:
class Player extends ISpriteInstance {
constructor() {
super();
}
jump() {
this.behaviors.Platform.vectorY = - this.behaviors.Platform.jumpStrength;
this.angleDegrees = 320;
}
tick() {
this.angleDegrees += 60 * this.runtime.dt;
}
}
runOnStartup(async runtime => {
runtime.objects.Player.setInstanceClass(Player);
runtime.addEventListener("beforeprojectstart", () => {
runtime.addEventListener("mousedown", (e) => {
const Player = runtime.objects.Player.getFirstInstance();
if(Player) {
Player.jump();
}
});
runtime.addEventListener("tick", () => {
const Player = runtime.objects.Player.getFirstInstance();
if(Player) {
Player.tick();
}
});
});
});
Everything works fine exept the jumping part. The bird is rotated but no jumping force (vectorY) is applyed. It seems that this is only a read only value. The documentation says, that you can also edit the value (https://www.construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/behavior-interfaces/platform). What am I doing wrong?!