Draxy

Members
  • Content Count

    13
  • Joined

  • Last visited

About Draxy

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I have a two player mini game, with all the main logic happening in this: function SpriteDoObj(player){ // global function this.player = player; this.atk = function(opponent) { this.opponent = opponent; if (this.player.overlap(opponent)) { //call miss sound here console.log("miss"); return; } else if (this.isSameAtkPosition(opponent)) { //call block sound console.log("block"); return; } else { console.log("hit!"); //call damage sound opponent.health --; } }; } //has been simplified And I make two instances of SpriteDoObj with: this.blueSpriteDo = new SpriteDoObj(blue_player); this.redSpriteDo = new SpriteDoObj(red_player); //.. also the players are made like this: this.players = this.game.add.physicsGroup(); var red_player = this.players.create(window.innerWidth, this.world.height - 490, 'red_spritesheet'); var blue_player = this.players.create(0, this.world.height - 490, 'blue_spritesheet'); And the atk function is called like this: if (blue_keyMap.atk.isDown) { this.blueSpriteDo.atk(this.redSpriteDo); //the parameter for the atk function //passes the opposite player, that becomes the opponent } The error is phaser.js:47751 Uncaught TypeError: displayObject.getBounds is not a function And I'm not sure why this is happening, mayhaps something to do with how I'm passing the objects around, but it looks good to me - though I'm a noob. Any Ideas?
  2. I never knew this was a thing, and it works! Thank you!
  3. I have a player in a group like this: this.players = this.game.add.physicsGroup(); blue_player = this.players.create(0, this.world.height - 490, 'blue_player'); this.players.setAll('body.bounce.y', 0.2); this.players.setAll('body.gravity.y', 1000); this.players.setAll('collideWorldBounds', true); blue_player.animations.add('idle',[0,1,2],2.1,true); this.players.callAll('animations.play', 'animations', 'idle'); And I add a function to my game prototype that is called by my update function: blue_controls: function () { if (blue_keyMap.jump.isDown) { console.log("blue is going up in the world"); this.players.blue_player.body.velocity.y = 2000; } }, And get: TypeError: Cannot read property 'body' of undefined The error is with this line: this.players.blue_player.body.velocity.y = 2000; I have tried just this.blue_player.body.velocity but get blue_player undefined, and others. I've ran out of things to try that I can think of. I know I'm not referencing the object correctly, but I'm currently putting in the milage to learn object Inheritance and prototypes - and using this game I'm making as practice. I'm just a little stuck, help a noob out?
  4. Thank you both for your time! Works fine now, I've learnt a lot from this, thanks again
  5. Thanks for your reply @samid737, you helped me out a lot! But now the physics seem broke, am I referencing the players right? My code now: myGame.Game.prototype.create = function () { this.players = this.game.add.physicsGroup(); var red_player = this.players.create(900, this.world.height - 490, 'red_player'); var blue_player = this.players.create(0, this.world.height - 490, 'blue_player'); this.players.setAll('enableBody', true); //added this and the line below to see if I could get them to fall this.players.physicsBodyType = Phaser.Physics.ARCADE; this.players.setAll('body.bounce', 0.2); this.players.setAll('body.gravity', 1000); this.players.setAll('collideWorldBounds', true); blue_player.animations.add('idle',[0,1,2],2,true); red_player.animations.add('idle',[0,1,2],2,true); this.players.callAll('animations.play', 'animations', 'idle'); };
  6. I want to make a group called players and then assign things to it like this.players.body.gravity.y = 1000;, etc then make a red and blue player from that group that are identical but for the spreadsheets used, so i don't have to set gravity and other things of the sort twice for each. Are groups the best way to do this? I've tried with this code, but get "TypeError: Cannot read property 'bounce' of undefined" as an error myGame.Game.prototype.create = function () { console.log("create is working"); this.platforms = this.add.physicsGroup(); this.platforms.enableBody = true; this.platforms.setAll('body.immovable', true); var ground = this.platforms.create(0, this.world.height - 64, 'ground'); ground.scale.setTo(2, 2); ground.visible = false; var background = this.add.sprite(0, 0, 'background'); background.animations.add("background", [0,1,2,3,4,5,6,7,8], 10, true); background.animations.play("background"); background.width = this.game.width; background.height = this.game.height; this.world.sendToBack(background); //used this to place background behind platforms this.players = this.game.add.group(); //make player group this.players.body.bounce.y = 0.2; //give play group things so that red_player and blue_player this.players.body.gravity.y = 1000;//will have them this.players.body.collideWorldBounds = true; this.players.blue_player.animations.add('idle', [0, 1, 2], 2, true); this.players.animations.play('idle'); var red_player = this.players.create(10000, this.world.height - 490, 'red_player'); var blue_player = this.players.create(0, this.world.height - 490, 'blue_player'); this.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(this.blue_jump, this); }; My knowledge of objects is terrible, but I can see any problems with what I've done, can anyone help me out? Thanks for reading.
  7. Noob here, I'm trying to get an update function to call inside a separate JS file. I have a basic phaser structure in load.js: var myGame = {}; myGame.load = function (game) { }; myGame.load.prototype = { preload: function() { //.. }, create: function(){ //... } }; myGame.update = function(game) { }; myGame.load.prototype = { update: update }; And the update function I'm trying to add and call in update.js update = function() { game.physics.arcade.collide(blue_player, platforms); console.log("update is working"); }; load.js is loaded before update.js in my HTML Thanks a lot for reading
  8. Thanks for the reply! I did fix this with game.world.sendToBack(background); to place the background behind the ground, that was the main problem. Thanks for your time!
  9. Noob here, Having a hard time with making game states to work - I've been following tutorials and still no luck. I'm really looking for an overview of what I have so far on states, more so than an error fix (witch is loadState is not defined in index.html line 23) HTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>game v1</title> <script src="phaser.js"></script> <script src="jquery-3.2.1.js"></script> <script src="loadState.js"></script> <script src="update.js"></script> <link rel="stylesheet" href="css/game.css"> </head> <body> <div class="gameDiv"></div> </body> <script type="text/javascript"> (function() { var width = window.innerWidth; var height = window.innerHeight; var game = new Phaser.Game(width, height, Phaser.AUTO, 'gameDiv'); game.state.add("loadState",loadState); game.state.add("updateState",updateState); game.state.start("loadState"); })(); </script> </html> loadState.js: var loadState = { preload: function() { game.load.spritesheet("background" , "assets/backgroundgif2.png", 800, 336); game.load.image("ground","assets/red.png"); game.load.spritesheet("blue_player", "assets/player_sprites/playertwo standing.png", 96, 96); }, create: function(){ game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; game.physics.startSystem(Phaser.Physics.ARCADE); platforms = game.add.group(); platforms = game.add.physicsGroup(); var background = game.add.sprite(0, 0, 'background'); background.animations.add("background", [0,1,2,3,4,5,6,7,8], 10, true); background.animations.play("background"); background.width = game.width; background.height = game.height; game.world.sendToBack(background); //used this to place background behind platforms var ground = platforms.create(0, game.world.height - 64, 'ground'); platforms.enableBody = true; platforms.setAll('body.immovable', true); ground.scale.setTo(2, 2); ground.alpha = 0; //used this to make the ground transparent blue_player = game.add.sprite(-10, game.world.height -490, 'blue_player'); game.physics.arcade.enable(blue_player); blue_player.body.bounce.y = 0.2; blue_player.body.gravity.y = 300; blue_player.body.collideWorldBounds = true; blue_player.animations.add('idle', [0, 1, 2], 2, true); blue_player.animations.play("idle"); game.state.start("updateState"); } }; and updateState.js: I have also had var updateState error as undefined, witch does not happen in the tutorials I've used. Though this does not happen now with the code you see here. console.log("update is working"); var updateState = { update: function() { game.physics.arcade.collide(blue_player, platforms); } }; Thanks for reading, hope you can set me straight.
  10. I've updated it to show all my code, could you please take another look? I'd really appreciate it.
  11. Hi, I am noob, and this is a nooby question. I've looked everywhere for a fix, but I can't get my ground to show, I'm not sure if it's even there. My code: (updated to show all my code so far) <!doctype html> <html> <head> <meta charset="UTF-8" /> <title>hello phaser!</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="phaser.js"></script> <link rel="stylesheet" href="game.css"> </head> <body> <script type="text/javascript"> window.onload = function() { var width = $( document ).width(); var height = $( document ).height(); var game = new Phaser.Game(width, height, Phaser.AUTO, '', { preload: preload, create: create }); function preload () { //800 336 game.load.spritesheet("background" , "backgroundgif1.png", 800, 336); game.load.image("ground","red.png"); game.load.spritesheet("blue_player", "player_sprites/playertwo standing.png", 96, 96); } function create () { game.physics.startSystem(Phaser.Physics.ARCADE); platforms = game.add.group(); platforms = game.add.physicsGroup(); platforms.enableBody = true; var ground = platforms.create(400, 450, 'ground'); platforms.setAll('body.immovable', true); ground.scale.setTo(2, 2); var background = game.add.sprite(0, 0, 'background'); background.animations.add("background", [0,1,2,3,4,5,6,7,8], 10, true); background.animations.play("background"); background.width = game.width; background.height = game.height; blue_player = game.add.sprite(-10, game.world.height -490, 'blue_player'); game.physics.arcade.enable(blue_player); blue_player.body.bounce.y = 0.2; blue_player.body.gravity.y = 300; blue_player.body.collideWorldBounds = true; blue_player.animations.add('left', [0, 1, 2], 2, true); blue_player.animations.play("left"); } function update() { game.physics.arcade.collide(blue_player, platforms); } }; </script> </body> <script src="update.js"></script> </html> Any ideas as to what I'm doing wrong?