Trying to Update vectorY via JavaScript

0 favourites
  • 1 posts
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • 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;
    	}
    }

    And a StartUp Script:

    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?!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)