lemmikens

Members
  • Content Count

    5
  • Joined

  • Last visited

  1. Hi there, I want to return a variable from inside the "Create()" function and use it inside of the "Update()" function. This is kind of a two part question. First of all, how would I use the variable updateStart below in the Phaser "Update()" function? It seems that even when I make it global, that startUpdate never gets set when it's inside of a function. Secondly, my game has to do with player movement after the create function after that updateStart function is set. Is the right way to go about it? Any suggestions would be greatly appreciated. This is only part of my "create()" function, by the way. I truncated a lot of it for readability. Thanks! function create(){ this.input.on('drop', function (pointer, gameObject, dropZone) { gameObject.x = dropZone.x; gameObject.y = dropZone.y-65; setXY = [dropZone.x, dropZone.y]; console.log("x = " + dropZone.x + ", y = " + dropZone.y); dropZone.clearTint(); //makes it so 'mans' can still receive input after drop gameObject.input.enabled = true; clickButton .setInteractive() .on('pointerdown', function(pointer){ locked_in = this.add.image(400,400,'locked_in'); startSpots.clear(true, true); gameObject.input.enabled = false; tween = this.tweens.add({ targets: locked_in, x: 400, // '+=100' y: 300, // '+=100' ease: 'Elastic.easeInOut', // 'Cubic', 'Elastic', 'Bounce', 'Back' duration: 2500, repeat: 0, // -1: infinity yoyo: false, alpha: { getStart: () => 1.0, getEnd: () => 0 }, onComplete: () => { } }); clickButton.destroy(); clickButton.disableInteractive(); updateStart = true; }.bind(this)); }.bind(this)); } function update (updateStart) { console.log('update'); if (updateStart == true) { console.log('bleh'); } }
  2. lemmikens

    Can't create image 2 conditionals in

    Thanks, appreciate the suggestion. Still pretty new to JS... How exactly do I bind the original scope to the function? Thanks!
  3. lemmikens

    Can't create image 2 conditionals in

    Hi there, I'm trying to create an image and a tween to go along with it after a couple conditionals and it can't seem to get it right. Any help is greatly appreciated! var locked_in; var tween; this.input.on('drop', function (pointer, gameObject, dropZone) { gameObject.x = dropZone.x; gameObject.y = dropZone.y-60; dropZone.clearTint(); //makes it so 'mans' can still receive input after drop gameObject.input.enabled = true; //heroDown = true; clickButton .setInteractive() .on('pointerdown', function(pointer){ console.log(startSpots); startSpots.clear(true, true); gameObject.input.enabled = false; locked_in = this.add.image(400,400,'locked_in'); tween = this.tweens.add({ targets: locked_in, x: 400, // '+=100' y: 300, // '+=100' ease: 'Linear', // 'Cubic', 'Elastic', 'Bounce', 'Back' duration: 1000, repeat: 0, // -1: infinity yoyo: false }); } );
  4. lemmikens

    Extending Phaser.GameObjects.Sprite Class?

    Samme, you have given so may correct answers to so many of these posts. Thanks for taking care of this one, too! Can I ask what exactly this does? Particularly the "existing part" this.add.existing(...) Much appreciated!
  5. Hi, I've checked a couple posts on this forum regarding extending classes in Phaser, but get confused on how it exactly works, below is the code I'm trying to implement to add stats to a sprite: class spriteStats extends Phaser.GameObjects.Sprite { constructor (scene, x, y,myExtra) { super(scene, x, y); this.setTexture('../assets/testsprite.png'); this.setPosition(x, y); } setStats(speed, jump){ var stats = { "speed": speed, "jump": jump, } } getStats(){ return stats } } But when I attempt to create the sprite: var hero = this.add.spriteStats(100, 450, 'hero',0).setInteractive(); hero.setStats(5,5); it gives me a: "Uncaught TypeError: this.add.spriteStats is not a function". I don't think I'm extending the class correctly. Please forgive me, as I'm still relatively new to JavaScript. Thanks!