Search the Community

Showing results for tags 'weapon'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 20 results

  1. Hi, I am really confused why I am getting errors with this code from the weapon plugin: create: function() { //load current level this.loadLevel(); this.weapon = this.game.add.weapon(-1, 'explode'); this.weapon.fireFrom.setTo(300,300, 1, 1); this.weapon.bulletKillType = Phaser.Weapon.KILL_CAMERA_BOUNDS; this.weapon.bulletGravity.y = -1000; this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR) .onDown.add(this.weapon.fire, this); The error is: phaser.js:100951 Uncaught TypeError: Cannot read property 'width' of undefined at Object.Phaser.Weapon.fire (phaser.js:100951) It seems to be an issue with the context, but I have tried this.weapon, this.state, this.game all to no avail. Annoyingly if I run ZPlat.GameState.weapon.fire() from the console it shoots fine. If anyone can see what I'm doing wrong I'd be very grateful. Thanks, Gordon
  2. Hi, I'm currently in the process of making my first game having completed the zenva course and am confused by the weapon plugin. My game is a platformer shootemup type, where there will be the player and multiple enemies shooting a variety of ammo types. The zenva course covers making bulletpools and sharing them between enemy sprites, but does not mention the weapon plugin. On the face of it the weapon plugin looks great, sorting out a whole load of features neatly. However if each enemy has its own weapon tracking it, does that mean that it then gets its own bullet pool, all of which then need to be destroyed once the enemy is killed? This seems to somewhat defeat the point of the bullet pool. My question is then: can the bullet pools be shared between enemies OR should I just rely on the entire bulletpool being recycled along with the enemy itself as it is itself pooled OR should I just not bother with the weaponplugin at all? Any help or suggestions much appreciated, Thanks, Gordon
  3. weapon.fire() return null

    Hi all, I've a problem with weapon.fire(), he return null. here, a part of my code (where i use weapon)
  4. Weapon Plug in and P2

    Is there a way to get collisions to work with p2, or to go through the list of active bullets and get thier x and y location, Or what do I loose if I switch from p2 to arcade. Thanks
  5. Euhm scaling a weapon/bullets

    Hello, I created weapon animated from a spritesheet however the images on the sheet where a bit oversized. I know I can make the spritesheet smaller but it kindoff defeats my purpose of learning more in programming;) So when I scaled the weapon itself (fireball) to be half its sprites size its starting position also changed. Therefore I figured I' d anchor the weapon in the right position. But for some reason it keeps stating " anchor = undefined". So, anyone sees whats going wrong here? //This line is the one bugging out. I tried setting the anchor on each bullet and on the weapon itself. The console states 'anchor is undefined" this.weapon.anchor.setTo(0.5, 0.5); var weapon; create: function () { game.world.setBounds(0, 0, 1920, 560); game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.gravity.y = 1000; this.weapon = game.add.weapon(1, "fireball"); // here I scale the weapon the fireball this.weapon.bullets.scale.setTo(0.5); this.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; this.weapon.bulletSpeed = 300; this.weapon.fireRate = 500; //will use more sprites in the near future this.weapon.addBulletAnimation('fire',[23], 10, true ); this.weapon.trackSprite(player, 0, 0 , false); this.weapon.allowGravity = false; this.weapon.bulletGravity.y = -1000; //here I attempt to set the anchor so the weapon will be pushed to the right startposition this.weapon.anchor.setTo(0.5, 0.5); //this.weapon = action.attack.weapon; console.log(this.weapon); //u create controls cursors = game.input.keyboard.createCursorKeys(); //register hotkey this.fire = game.input.keyboard.addKey(Phaser.Keyboard.W); // Stop the following keys from propagating up to the browser game.input.keyboard.addKeyCapture([Phaser.Keyboard.E]); },
  6. Hi, In the documentation of the Weapon, the property bulletClass speak the follow: bulletClass : Object => "The Class of the bullets that are launched by this Weapon. Defaults Phaser.Bullet, but can be overridden before calling createBullets and set to your own class type." that could be written: class MyWeapon extens Phaser.Weapon { contructor(){ super(); this.bulletClass = MyBulletClass; /*error here*/ this.createBullets(30, imgSprite); } } the problem is that que the method bulletClass executes internally the code: https://github.com/photonstorm/phaser/blob/v2.6.2/src/plugins/weapon/WeaponPlugin.js#L1130 this.bullets.classType = this._bulletClass; But this.bullets still not was instantiate(null), so throws the error "can not read property 'classType' of undefined". If i comments the line, everything works. Would this line really necessary? I'm using Phaser 2.6.2.
  7. Hi, I'm writing a class that extends Phaser.Weapon and i want that the method update() keep running, like this: class MissileWeapon extends Phaser.Weapon { constructor(game: Phaser.Game){ super(game, game.plugins); } update(){ /*this not execute*/ } } But it not running. If i add this "hack": class MissileWeapon extends Phaser.Weapon { constructor(game: Phaser.Game){ super(game, game.plugins); /*the hack*/ this.active = true; /*active plugin*/ this.hasUpdate = true; var test = game.plugins.add(Phaser.Weapon); /*Only for the game.plugins(PluginManager) start running*/ game.plugins.plugins.push(this); /*add my weapon in the PluginManager*/ } update(){ /*executing */ } } It seems that when extends of plugin Weapon, it not is added direct in the game.plugins (PluginManager), then the method update not executes. How could i make this without uses the "hack"? and i'm using Phaser version 2.6.2 thanks :-)
  8. Hi there, I want to build a shotgun weapon for my game. This shotgun would shoot 3 (or more) bullets in a conical angle. However, from what I see, Phaser.Weapon only fires one bullet at a time. What do I do in order to get the weapon to fire 3 bullets consecutively
  9. How do you extend Phaser.Weapon?

    Hi there, I want to extend Phaser.Weapon so I can create my own custom weapons. I know that you extend groups by using Weapon.SingleBullet = function (game) { Phaser.Group.call(this, game, game.world, 'Single Bullet', false, true, Phaser.Physics.ARCADE); return this; }; Weapon.SingleBullet.prototype = Object.create(Phaser.Group.prototype); Weapon.SingleBullet.prototype.constructor = Weapon.SingleBullet; But what about the weapons group? Are there any examples out there for this? EDIT: I used Weapon.SingleBullet.prototype = Object.create(Phaser.Weapon.prototype); and it seems to work. However, when I try to fire my bullet I get the following error Cannot read property 'getFirstExists' of null at Pistol.Phaser.Weapon.fire (phaser.js:101053)
  10. weapon.prototype problem

    hi, i'm searching to make a prototype with the weapon class but that don't work. i have this error : phaser.min.js:6 Uncaught TypeError: a.parent.removeChild is not a function at c.World.b.DisplayObjectContainer.addChildAt (phaser.min.js:6) at c.World.b.DisplayObjectContainer.addChild (phaser.min.js:6) at c.World.c.Group.add (phaser.min.js:11) at c.GameObjectFactory.existing (phaser.min.js:14) at Object.create (main.js:322) at c.StateManager.loadComplete (phaser.min.js:10) at c.StateManager.preUpdate (phaser.min.js:10) at c.Game.updateLogic (phaser.min.js:12) at c.Game.update (phaser.min.js:12) at c.RequestAnimationFrame.updateRAF (phaser.min.js:18) however i take this from these example https://phaser.io/examples/v2/weapon/asteroids what 's wrong ? Thanks. weapon = function(){ Phaser.Weapon.call(this,game,20,'rect') this.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; // Because our bullet is drawn facing up, we need to offset its rotation: this.bulletAngleOffset = 90; // The speed at which the bullet is fired this.bulletSpeed = 400; // Speed-up the rate of fire, allowing them to shoot 1 bullet every 60ms this.fireRate = 60; // Add a variance to the bullet angle by +- this value this.bulletAngleVariance = 10; this.canon = game.add.sprite(320, 500, 'rect'); game.physics.arcade.enable(this.canon); // Tell the Weapon to track the 'player' Sprite, offset by 14px horizontally, 0 vertically this.trackSprite(this.canon, 14, 0); } weapon.prototype = Object.create(Phaser.Weapon.prototype) weapon.prototype.constructor = weapon weapon.prototype.update = function() { this.fire() } var game_state = { create: function(){ game.physics.startSystem(Phaser.Physics.ARCADE) this.canon=new weapon() game.add.existing(this.canon) }, }
  11. How to add sounds to Weapon?

    Currently, in my game. I've done the following if (player.fireButton.isDown) { //firing straight up player.weapon.fireAngle = Phaser.ANGLE_UP; player.weapon.fire(); this.shootSfx.play(); } The issue with this is that when I hold down the `fireButton` the first millisecond of the sound is played on a loop. Basically, the sound just keeps resetting. How do I set it up so that it has to play the full sound clip before starting again? Also, are there any Phaser examples of sounds and weapons being used together?
  12. How to not apply gravity to weapon?

    Hi there, I'm creating a simple platform game where you can shoot enemies. I've applied game.physics.arcade.gravity.y = 1000; But this seems to now affect my weapon class and bullets too! How do I set my weapons or bullets to NOT be affected by gravity? Here's the code I've used for reference: var playState = { //code to make assets goes here create: function(){ /*-- creating player --*/ game.add.sprite(0, 0, 'background'); game.physics.arcade.gravity.y = 1000; //Do not enable, need to fix gravity. this.player = game.add.sprite(game.width/2, 780, 'player'); this.player.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(this.player); this.player.body.gravity.y = 1500; this.player.body.bounce.set(0.3); this.player.body.collideWorldBounds = true; this.player.cursor = game.input.keyboard.createCursorKeys(); this.player.fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); this.player.hp = 100; this.player.weapon = game.add.weapon(30, 'bullet'); // this.player.weapon.enableBody = true; this.player.weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; this.player.weapon.bullets.setAll('body.gravity.y', 0); this.player.weapon.bulletSpeed = 850; this.player.weapon.fireRate = 200; this.player.weapon.trackSprite(this.player);
  13. Extend Weapon Plugin (TypeScript)

    Hello, I'm trying to make separate weapon classes in an Asteroids-type game, for example a Missile.ts, Laser.ts, etc. What I have so far is this (Missile.ts): module Spaceroni { export class Missile extends Phaser.Weapon { constructor(game: Phaser.Game) { super(game, game.plugins); this.bulletKillType = Phaser.Weapon.KILL_LIFESPAN; this.bulletSpeed = 1500; this.fireRate = 20; } } } In my Player.ts I have weapon: Spaceroni.Missile; up top and I'm adding a weapon in its constructor with this.weapon = game.add.weapon(30, 'missile'); This isn't working (bulletSpeed and fireRate aren't changing), I think because game.add.weapon() creates a new weapon instance, separate from my Missile class. I would like to avoid putting all of this Missile-specific code directly into the Player class since I want to be able to change the weapon based on power-ups, as well as add the Missile weapon to enemies. Any ideas on how to properly extend the weapon plugin? Thanks in advance!
  14. Weapon plugin bullet bounce

    Hello, I am new to Phaser and I am trying to make the bullet bounce in the y axis in Phaser. Does anyone know how to do it? Thank you.
  15. var player; var keys; var shootButton; var bullet; function create() { //game.add.sprite(0,0, 'background'); game.physics.startSystem(Phaser.Physics.ARCADE); //creates player player = game.add.sprite(0.45*600,600-50,'galaga'); game.physics.arcade.enable(player); // allows player to fire 2 bullets bullet = game.add.weapon(2,'bullet'); // when bullet leaves the screen, it will be destroyed bullet.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; // offset rotation bullet.bulletAngleOffset = 90; // prevents ship from auto firing bullet.autofire = false; // The speed at which the bullet is fired bullet.bulletSpeed = 400; //keeps track of how many bullets were shot bullet.shots = 0; // Tell the bullet to track the 'player' Sprite, offset by 16px horizontally, 0 vertically bullet.trackSprite(player, 16, 0); //enabling keyboard use keys = game.input.keyboard.createCursorKeys(); shootButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); } function update() { // Reset the players velocity (movement) player.body.velocity.x = 0; if (keys.left.isDown) { // Move to the left player.body.velocity.x = -150; } else if (keys.right.isDown) { // Move to the right player.body.velocity.x = 150; } else { //ship is idle } //shooting the bullet if (shootButton.isDown) { bullet.fire(); } } What I'm trying to do is prevent my player variable from autofiring(holding down space button to fire bullets.). I want the player to be able to shoot two bullets at a time, but only when the player presses the fire button rather than holding it. I was under the impression that bullet.autofire = false; would do the trick, but I was wrong. Am I using the autofire variable the wrong way?
  16. BusterBros Style Hookshot Weapon

    Hey all! I'm working on a top-down geolocational version of Buster Bros (or Pang if you prefer), and I'm trying to get a similar hookshot type weapon, but I'm not entirely sure how to go about creating a weapon that grows from the player, and dies when it hits an enemy or a boundary. Right now I'm just using the standard weapon.bullets, but I'd love suggestions! Code is public on GitHub here.
  17. Hello! In begin I want to apologize for my English. I am using mesh.attachToBone for mount my pistol with character hand. All works fine. But when I am using bone.updateMatrix for rotate character torso var mat = this.torso.getLocalMatrix(); mat = mat.multiply(BABYLON.Matrix.RotationX(r)); this.torso.updateMatrix(mat); Torso rotates correctly, but my pistol still in place. On left screen you can see how work pistol.attachToBone, on right screen it is when I am changed torso rotation, but pistol did not move.
  18. Weapon plugin bullet wrong angle

    I´m having a problem with the weapon plugin. When I use the function weapon.fire() it fires a bullet 90 degrees from the canon sprite (the one the weapon plugin is tracking). Any idea what I am doing Wrong? Thnxs!
  19. The height of bullets varies by ±1px

    When the sprite tracked by weapon moves up and down, bullets generated on some heights are made one pixel taller or lower. See screenshot: Initialization code: this.scrolls = game.add.weapon(40, 'lvl1', 'scroll') this.scrolls.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS this.scrolls.bulletSpeed = 50 this.scrolls.fireRate = 10 this.scrolls.fireAngle = 0 this.scrolls.trackSprite(this.spike, 13, 5) I've checked if fireFrom position is somehow made fractional but logging shows it remains integer. The bulletAngleVariance property is set to zero by default. What another can cause such behavior?