Faizy

Members
  • Content count

    13
  • Joined

  • Last visited

  1. Hey, I want my game to be the size of the white area(as linked below) and the grey area should still be able to interact with the game(white area) via (Phaser-)buttons etc. meanwhile the gamestage/gamearea should only be on the white rectangular. Is that possible? I´m looking for something to create "walls". https://gyazo.com/81b7432d89f108a0b15c231e1ab6f4bc Thank you
  2. Thanks rich. Wel,; I´ll ask another question, assuming the following: var game = new Phaser.Game(800, 600, Phaser.Auto, '', { preload: preload, create: create, update: update } ); Is it possible to ONLY use 700px instead of 800px width? I would use the 100px to place my buttons there. Is there a way to say phaser that the game, where everything happens, is only 700px width?
  3. No, phaser.js buttons, like the following one: buttonSpawnPlayerTower = game.add.button(550, 0, 'buttonSpawnPlayerTower', drawGrid, this, null, null, null);
  4. Hey, let´s say I created var game = new Phaser.Game(800, 600, Phaser.Auto, '', { preload: preload, create: create, update: update } ); Now I want buttons, which are next to the stage. They dont influence anything on the field. However, they should "talk"(e.g. do x when button is pressed) to the game objects. How could I realise this? Basically I´m looking for the best way to add things outside the "true" stage, which still can interact with the game, but are not on the true "stage" Thanks
  5. Let´s say I want an hp bar over the enemy. Is it possible to bind the hp bar to the enem? So that it moves whereever the enemy is moving? Sure, I could realise this by saying the following in the update function: hpbar.image.x = enemy.image.x hpbar.image.y = enemy.image.y But is there another way?
  6. Hm, it says exactly what I have (said) above. Or am I missing something?
  7. Thanks. I got a new problem now though. Code: //window.location.reload(true) //Clear Cache var player, enemy; var playerMovementX = 10; var playerMovementY = 10; var playerMovementStandbyX = 3; var playerMovementStandbyY = 3; var game = new Phaser.Game(800, 600, Phaser.Auto, '', { preload: preload, create: create, update: update } ); function preload() { game.load.image('player', 'assets/playerDefault.png') game.load.image('enemy', 'assets/enemyDefault.png') game.load.image('playerBullet', 'assets/playerBullet.png') } function create() { game.stage.backgroundColor = '#3598db' game.physics.startSystem(Phaser.Physics.ARCADE); player = new Player(); enemy = new Enemy(); } function update() { //Collision game.physics.arcade.collide(player.image, enemy.image, null, null, null); game.physics.arcade.collide(player.weapon.bullets, enemy.image, enemyKill, null, null); //Player: movement player.image.rotation = game.physics.arcade.angleToPointer(player.image) if (player.left.isDown) { player.image.body.velocity.x -= playerMovementX; } else if (player.right.isDown) { player.image.body.velocity.x += playerMovementX; } /*else { player.image.body.velocity.x = playerMovementStandbyX; }*/ if (player.up.isDown) { player.image.body.velocity.y -= playerMovementY; } else if (player.down.isDown) { player.image.body.velocity.y += playerMovementY; } //Player: fire if (game.input.activePointer.leftButton.isDown) { console.log("Fire") player.weapon.fire(); } } Enemy = function () { var x = game.world.randomX; var y = game.world.randomY; this.health = 3; this.image = game.add.sprite(x, y, 'enemy'); game.physics.arcade.enable(this.image); this.image.body.collideWorldBounds = true; } Player = function() { var x = game.world.centerX -25; var y = game.world.centerY -25; this.left = game.input.keyboard.addKey(Phaser.KeyCode.A) this.right = game.input.keyboard.addKey(Phaser.KeyCode.D) this.up = game.input.keyboard.addKey(Phaser.KeyCode.W) this.down = game.input.keyboard.addKey(Phaser.KeyCode.S) this.fireButton = game.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR); this.health = 10; this.image = game.add.sprite(x, y, 'player'); this.image.anchor.setTo(0.5, 0.5) game.physics.arcade.enable(this.image); this.image.body.collideWorldBounds = true; this.weapon = game.add.weapon(30, 'playerBullet'); this.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; this.weapon.bulletSpeed = 600; this.weapon.fireRate = 100; this.weapon.trackSprite(this.image, 0, 0, true); }; function enemyKill(bullet, enemy) { enemy.kill(); } If the players bullets(player.weapon.bullets) collide with the enemy(enemy.image) the function enemyKill should be executed as a callback: function update() { //Collision game.physics.arcade.collide(player.image, enemy.image, null, null, null); game.physics.arcade.collide(player.weapon.bullets, enemy.image, enemyKill, null, null); The collision signal works fine. However, the function will kill the bullet when it has enemy.kill() in it and will kill the enemy when it has bullet.kill(). function enemyKill(bullet, enemy) { enemy.kill(); } This doesnt makes sense to me, since the API Documentation says on the callback: "An optional callback function that is called if the objects collide. The two objects will be passed to this function in the same order in which you specified them, unless you are colliding Group vs. Sprite, in which case Sprite will always be the first parameter." Could someone help me out?
  8. Hi Cudabear, I changed my code like you suggested and it works perfectly fine now - thanks Is it actually somewhere descibed, or at least some information about the fact, that ARACDE PHYSICS need velocity to work? I couldn´t find anything about this in the API Documentation.
  9. EDIT: THIS PROBLEM WAS SOLVED BY CUDABEAR ALREADY!. The fifth post includes a new problem in the same context though! Could someone explain me why the collision isnt working? I expect(want) the "player.image" and "enemy.image" to not go "through" each other. What am I missing? Both(player.image and enemy.image) have the Aracde engine enabled. //window.location.reload(true) //Clear Cache var player; var enemy; var game = new Phaser.Game(800, 600, Phaser.Auto, '', { preload: preload, create: create, update: update } ); function preload() { game.load.image('player', 'assets/playerDefault.png') game.load.image('enemy', 'assets/enemyDefault.png') } function create() { game.stage.backgroundColor = '#3598db' game.physics.startSystem(Phaser.Physics.ARCADE); player = new Player(); enemy = new Enemy(); } function update() { game.physics.arcade.collide(player.image, enemy.image); if (player.cursor.left.isDown) { player.image.position.x -= 10; } else if (player.cursor.right.isDown) { player.image.position.x += 10; } else if (player.cursor.up.isDown) { player.image.position.y -= 10; } else if (player.cursor.down.isDown) { player.image.position.y += 10; } } Enemy = function () { var x = game.world.randomX; var y = game.world.randomY; this.health = 3; this.image = game.add.sprite(x, y, 'enemy'); game.physics.arcade.enable(this.image); } Player = function() { var x = 200; var y = 75; this.health = 10; this.image = game.add.sprite(x, y, 'player'); game.physics.arcade.enable(this.image); this.image.body.collideWorldBounds = true; this.cursor = game.input.keyboard.createCursorKeys(); }; Thank you
  10. Thanks scheffgames. I changed it, but I still run into the exact same problem. function create() { game.stage.backgroundColor = '#3598db' this.cursor = game.input.keyboard.createCursorKeys(); this.player = game.add.image(200, 75, 'tank') game.physics.arcade.enable(this.player); this.player.body.enable = true; this.player.body.collideWorldBounds = true; for (var i = 0; i < enemiesTotal; i++) { enemies.push(new EnemyTank()); } } Edit: I fixed it. I used images instead of sprites...images dont support physics.
  11. Can someone tell me why "body" is undefined? Console tells me: "Uncaught TypeError: Cannot set property 'enable' of undefined" function create() { game.stage.backgroundColor = '#3598db' this.cursor = this.input.keyboard.createCursorKeys(); this.player = this.add.image(200, 75, 'tank') this.physics.arcade.enable(this.player); this.player.body.enable = true; this.player.body.collideWorldBounds = true; for (var i = 0; i < enemiesTotal; i++) { enemies.push(new EnemyTank()); } } Can someone help me out?
  12. Hi rich, that makes sense - thank you! I have another question(I hope it´s ok that I´,ll put it in here). Let´s say I have the following code: var game = new Phaser.Game(800, 600, Phaser.AUTO, "", { preload: preload, create: create, update: update } ); function preload() { game.load.image("ground", "assets/ground.png") game.load.image("towerAtt", "assets/towerAtt.png") } function create() { groundField = game.add.group(); groundField.enablebody = true; ground = groundField.create(0, 0, "ground") ground.scale.setTo(game.width/ground.width, game.height/ground.height) //tower = game.add.image(0, 0, "towerAtt") } function update() { } Let´s say I want to create something(a tower) when a specific event happens(for example the user clicking a button). How would I do that? I´ll try to explain my thoughts and problems: since I dont want any towers to show up(place one tower after a user interaction), I cant paste tower = game.add.image(0, 0, "towerAtt") this in the create function, since it will get created(and shown), right? What would be a short solution to it? Thank you!
  13. Hey, first: I´m new to Phaser. I was reading the tutorial and I dont understand, why you dont have to set "game.physics.arcade.enable()" for platforms("game.physics.arcade.enable(platforms)"? In the tutorial it´s done for the player("game.physics.arcade.enable(player);") which makes sense. Later on the collision detection "game.physics.arcade.collide(player, platforms);" however looks for collisions between the player and the platforms. Shouldn´t playtforms be an Arcade Physics body as well? In the tutorial on player is getting up with it. Thank you!