lemmikens

Members
  • Content Count

    9
  • Joined

  • Last visited

  1. Adding the .bind() method to each conditional allowed me to use "this" inside of them: var locked_in; //var tween = 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){ locked_in = this.add.image(400,400,'locked_in'); console.log(startSpots); startSpots.clear(true, true); gameObject.input.enabled = false; tween = this.tweens.add({ targets: locked_in, x: 400, // '+=100' y: 300, // '+=100' ease: 'Cubic', // 'Cubic', 'Elastic', 'Bounce', 'Back' duration: 2, repeat: 0, // -1: infinity yoyo: false }); }.bind(this)); }.bind(this)); you can also do something like this = newThis and pass your "newThis" to whatever function you need. Both are helpful
  2. Just to elaborate on Rich's answer since it wasn't abundantly clear to me because I'm a noob and I had to fiddle with it a bit... this.input.setHitArea(groupName.getChildren()).on('gameobjectdown', function(pointer, gameObject) { });
  3. Hi There, What would be the best way to zoom into my game scene on Phaser 3 on a mobile device? Can I somehow do it like a normal zoom on a mobile site? I notice that the normal zoom only works on the "non-Phaser 3" part of my screen when I'm on mobile... is there a way to extend that to the "Phaser 3" part of my screen? Thank you!
  4. Like the Title says: I would like a game object (one) to become transparent only if another game object (two) is fully covered by the first object (one). What would be the best way about doing this? Thanks!
  5. 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'); } }
  6. Thanks, appreciate the suggestion. Still pretty new to JS... How exactly do I bind the original scope to the function? Thanks!
  7. 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 }); } );
  8. 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!
  9. 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!