pete796

Members
  • Content count

    16
  • Joined

  • Last visited

  1. pete796

    Enemy Inheritance

    ok, so this has been resolved, both enemies now behave as they should. flyingEnemy has its own patrol method
  2. pete796

    Enemy Inheritance

    Hi everyone, I'm trying to create two types of enemies, the first is a robot that has 2 methods: sleep and patrol. My second enemy is a flyingEnemy. The aim is to inherit the sleep method from the robot but amend the patrol method. Can anyone show me how my flyingEnemy can inherit from robot whilst amending the patrol method? Below is my code. When I create the flyingEnemy, its patrol method overwrites the robot's patrol method and ALL enemies have the same behavior. var SuperSmash = SuperSmash || {}; SuperSmash.flyingEnemy = function(game, x, y, key, velocity, tilemap, player) { "use strict"; SuperSmash.Enemy.call(this, game, x, y, key); this.game = game; this.tilemap = tilemap; this.player = player; this.animations.add("fly", [0]); }; SuperSmash.flyingEnemy.prototype = Object.create(SuperSmash.Enemy.prototype); SuperSmash.flyingEnemy.prototype.constructor = SuperSmash.flyingEnemy; SuperSmash.flyingEnemy.prototype.patrol = function() { "use strict"; SuperSmash.game.physics.arcade.moveToObject(this, this.player, 200); };
  3. pete796

    Function is undefined

    Hello, I'm creating, a player object with different states, e.g: onground, inair, etc I'm trying to assign a method to this.currentState. In the update loop, i'm calling this.currentState to run the assigned method (this.groundState), However, i'm receiving the following error 'this.currentState is not a function' SuperSmash.Player = function(game, x, y) { Phaser.Sprite.call(this, game, x, y, 'player'); this.game.physics.arcade.enable(this); this.speed = 500; this.airSpeed = 300; this.jumpPower = 400; this.inAir = true; this.hitGround = false; this.body.gravity.y = 1350; this.currentState = this.groundState; console.log(this.currentState); // undefined }; SuperSmash.Player.prototype = Object.create(Phaser.Sprite.prototype); SuperSmash.Player.prototype.constructor = SuperSmash.Player; SuperSmash.Player.prototype.update = function() { this.currentState(); }; SuperSmash.Player.prototype.groundState = function() { console.log('ground'); } };
  4. pete796

    ES6 syntax and groups

    Hi, I'm working through some Phaser tutorials and have questions regarding the code below (the es6 syntax is throwing me). I understand the code extends phaser,group, however, I'm unsure what: 1) the 'parent' parameter is used for. 2) this.create is used for. Any help is greatly appreciated export default class NumberBox extends Phaser.Group { constructor(game, bgasset, val, parent) { super(game, parent); this.create(0, 0 bgasset); } }
  5. pete796

    Phaser 3 Questions

    Hello Rich, Thanks for clarifying. My aim is to use my current resources (books, videos etc) to build a simple game using the current version of Phaser. Once there are enough training materials and demos available for v3, I will switch versions (hopefully the current tutorials will remain archived on the Phaser website). Many thanks
  6. pete796

    Phaser 3 Questions

    Hello, I'm currently in the process of learning JavaScript and Phaser using a variety of resources: YouTube, videos and books. I have a couple of questions regarding the release of Phaser 3. 1) Will Phaser 3 invalidate my current learning, will code I write today work with P3? 2) Will P3 invalidate my learning resources? 3) Can I continue using the current version once Phaser 3 is released? Many thanks
  7. pete796

    var vs. this

    thanks all, super explanations, much appreciated!
  8. pete796

    var vs. this

    ok. great, this is what I was looking for (no pun).. Many thanks
  9. pete796

    var vs. this

    Hi Milton, Sorry, this may be a dumb question, but I've lost you. I assume 'this' is for properties of an object, however, in the above we are creating a group of objects, therefore we use var? That's my hunch Many thanks
  10. pete796

    var vs. this

    Hello, Can someone explain why you would use a 'var' instead of 'this' ? In the example below variables are defined for 'var r' and 'var scale' buildSpaceRocks: function() { this.spacerockgroup = this.add.group(); for(var i=0; i<this.totalSpacerocks; i++) { var r = this.spacerockgroup.create(this.rnd.integerInRange(0, this.world.width), this.rnd.realInRange(-1500, 0), 'spacerock', 'SpaceRock0000'); var scale = this.rnd.realInRange(0.3, 1.0); r.scale.x = scale; r.scale.y = scale; this.physics.enable(r, Phaser.Physics.ARCADE); r.enableBody = true; r.body.velocity.y = this.rnd.integerInRange(200, 400); r.animations.add('Fall'); r.animations.play('Fall', 24, true); r.checkWorldBounds = true; r.events.onOutOfBounds.add(this.resetRock, this); } }, Many thanks
  11. Hi, When the cursor keys are pressed the player moves in the correct direction, however, it keeps moving even if the key is released. Can anyone help? createPlayer: function() { this.player = new ZPlat.Player(this, 100, 100); this.dude = this.add.group(); this.dude.add(this.player); }, update: function() { if(this.cursors.left.isDown) { this.player.body.velocity.x = -this.RUNNING_SPEED; this.player.scale.setTo(1, 1); this.player.play('walking'); } else if(this.cursors.right.isDown) { this.player.body.velocity.x =this.RUNNING_SPEED; this.player.scale.setTo(-1, 1); this.player.play('walking'); } else { this.player.frame = 2; this.player.animations.stop(); } if(this.cursors.up.isDown) { this.player.body.velocity.y = -this.JUMPING_SPEED; } if(this.player.body.y > this.game.world.height) { this.gameOver(); } },
  12. pete796

    Game object

    Hi Sam, Thanks for the info, I will use your suggested method
  13. pete796

    Game object

    Hi, Can someone explain the advantage of creating an object (veggies) and then attaching the game object to veggies ? In many examples, the game object is attached isn't attached to another object. Example 1 var Veggies = Veggies || {}; Veggies.game = new Phaser.Game(480, 320, Phaser.AUTO); Example 2 game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, "ph_game");
  14. pete796

    Group vs physicsGroup

    Hello, As per title, can anyone explain the difference between Group / physicsGroup and use cases for each? Many thanks for your help, P