Jump to content

Search the Community

Showing results for tags 'Phaser.Sprite'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Alright, I have racked my brain so hard over the past couple of hours. Why does my sprite position itself at a new position every time it is spawned? I am passing a pair of literal coordinates to the constructor for this Player class inherited from Phaser.Sprite. I have been looking at this issue too closely, and I think that I'm overlooking some really stupid mistake. My impression is that this issue might have something to do with the sprite scaling that I apply, but if I disable all of the scaling on the sprite, the issue seems to still persist. Additionally, I have suspicion that it might have to do with the this.spawnX variables being incorrectly set. I'm a JavaScript noob, I apologize. Here is the code for my FriarDude.Player class (sorry for the dump, but I honestly have no idea where in the code the issue lay): FriarDude.Player = function (game, x, y) { // Class variables this.facing = 'idle'; this.cursors = null; this.dead = false; this.invincible = true; this.lives = 3; this.restLevel = 1; this.toggleVisibilityTimerEvent = null; // Clone starting position this.spawnX = x; this.spawnY = y; // this.RUN_VELOCITY = 300; this.SPRITE_SCALE = 4; this.INVINCIBILITY_DURATION = 1000; // // Input this.cursors = game.input.keyboard.createCursorKeys(); // // Constructor Phaser.Sprite.call(this, game, x, y, 'sprite_sheet', 'foreground/friar/2_simple/idle/0000'); game.physics.arcade.enable(this); this.body.bounce.y = .5; this.body.setSize(24,32,0,0); this.body.gravity.y = 300; this.animations.add('idle', [ 'foreground/friar/2_simple/idle/0000', 'foreground/friar/2_simple/idle/0001', 'foreground/friar/2_simple/idle/0002' ], 4, true, false); this.animations.add('run', [ 'foreground/friar/2_simple/run/0000', 'foreground/friar/2_simple/run/0001' ], 8, true, false); this.anchor.setTo(.5,.5); this.scale.setTo(this.SPRITE_SCALE); this.spawn(); return this; //};FriarDude.Player.prototype = Object.create(Phaser.Sprite.prototype);FriarDude.Player.prototype.constructor = FriarDude.Player;FriarDude.Player.prototype.update = function() { if (this.dead) return; this.body.velocity.x = 0; if (this.cursors.left.isDown) { this.body.velocity.x = -this.RUN_VELOCITY; if (this.facing != 'left') { this.scale.x = -this.scale.x; this.facing = 'left'; this.animations.play('run'); } } else if (this.cursors.right.isDown) { this.body.velocity.x = this.RUN_VELOCITY; if (this.facing != 'right') { this.scale.x = this.scale.y; this.facing = 'right'; this.animations.play('run'); } } else { if (this.facing != 'idle') { this.animations.play('idle'); this.facing = 'idle'; } }}FriarDude.Player.prototype.spawn = function() { // Resetting properties that can be affected by dying this.dead = false; this.body.collideWorldBounds = true; this.animations.play('idle'); // // Reset velocity this.body.velocity.x = 0; this.body.velocity.y = 0; // // Reset position this.x = this.spawnX; this.y = this.spawnY; // // Temporary invincibility this.invincible = true; this.toggleVisibilityTimerEvent = this.game.time.events.loop(100, this.toggleVisibility, this); this.game.time.events.add(this.INVINCIBILITY_DURATION, this.endInvincibility, this); //}FriarDude.Player.prototype.kill = function() { this.dead = true; this.lives--; this.body.collideWorldBounds = false; this.animations.stop(); this.frameName = 'foreground/friar/2_simple/die'; // Launch the Player this.body.velocity.setTo(this.game.rnd.realInRange(-150, 150), -150); //}FriarDude.Player.prototype.endInvincibility = function() { this.invincible = false; this.game.time.events.remove(this.toggleVisibilityTimerEvent);}FriarDude.Player.prototype.toggleVisibility = function() { if (this.alpha > 0) this.alpha = 0; else this.alpha = 1;}
×
×
  • Create New...