Jump to content

Displaying Sprite inside game.stage with OOP


Jim07
 Share

Recommended Posts

Hello guys,

I trying to display sprite inside class object but there is nothing inside box game, my code :

class Player{
	constructor(lifeMax = 3){
		this.lifeMax = lifeMax;
		this.life = this.lifeMax;
		this.scorePlayer = 0;
		this.velocLeft = 0;
		this.velocRight = 0;
		this.velocUp = 0;
		this.velocDown = 0;
		this.tabBullets = [];
		this.sprite = new PIXI.Sprite(loader.resources["ASSETS/SPRITES/spaceship.png"].texture);
		this.sprite.anchor.set(0.5, 0.5);
		this.sprite.position.set(196, 196);
		this.delayShoot = 1500;
		this.timerShoot;
		game.stage.addChild(this.sprite);
		//this.shoot();
	}

	/*
	shoot(){
		this.timerShoot = setInterval(function(){
			let objBullet = new LaserBullet(1, -2.0, new PIXI.Sprite(loader.resources['ASSETS/SPRITES/bullet.png'].texture), this.sprite.x, this.sprite.y - 16);
			//objBullet.sprite.position.set(this.sprite.x, this.sprite.y - 16);
			this.tabBullets.push(objBullet);
			game.stage.addChild(objBullet.sprite);
		}, this.delayShoot);
					
	}
	*/

	takeDamages(bulletEnemy){
		this.life -= bulletEnemy.damages;
		if(this.life <= 0){
			game.stage.removeChild(this.sprite);
		}
	}
}

After i instanciate Player object but the spaceship of player don't display

let player = new Player();

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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