Jump to content

Euhm scaling a weapon/bullets


Dlost1
 Share

Recommended Posts

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]);
 
},

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...