Dlost1 Posted April 25, 2017 Share Posted April 25, 2017 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 More sharing options...
samme Posted April 25, 2017 Share Posted April 25, 2017 weapon.bullets is a Group and has no anchor property. Use instead: weapon.bullets.setAll('scale.x', 0.5); weapon.bullets.setAll('scale.y', 0.5); Dlost1 1 Link to comment Share on other sites More sharing options...
Dlost1 Posted April 25, 2017 Author Share Posted April 25, 2017 Thats it! Thank you! But..how did you know to use 'scale.x' ? This is something you just " have to know' ...or is there any logic to it I am missing out on? Link to comment Share on other sites More sharing options...
Cudabear Posted April 25, 2017 Share Posted April 25, 2017 https://photonstorm.github.io/phaser-ce/Phaser.Group.html#setAllChildren It lists an example under the documentation here. Dlost1 1 Link to comment Share on other sites More sharing options...
Recommended Posts