Jim07 Posted August 16, 2021 Share Posted August 16, 2021 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(); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted August 16, 2021 Share Posted August 16, 2021 are you sure that resources are already loaded when you create it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.