neonwarge04 Posted August 25, 2015 Share Posted August 25, 2015 I was not permitted to use Phaser.js so I am stuck doing this on Pixi.js. Though I am using tween.js, I can't seem to make my class work. I can, if I start to dim in (opacity 1 to 0), but not dim out (opacity 0 to 1). I wonder what I got wrong. Here is my class: function Dimmer(stage , screenSize , dimSpeed , color , maxOpacity){ this.mStage = stage; this.mScreenSize = screenSize; this.mDimSpeed = dimSpeed; var mDimmerQuadrant = new PIXI.Graphics(); mDimmerQuadrant.lineStyle(0 , 0x000000 , 0); mDimmerQuadrant.beginFill(color , 0); mDimmerQuadrant.drawRect(0 , 0 , this.mScreenSize.width , this.mScreenSize.height); this.mFadeOut = new TWEEN.Tween({alpha : mDimmerQuadrant.alpha}) .to({alpha : 1} , this.mDimSpeed) .onStart(function() { this.alpha = 0; }) .onUpdate(function() { mDimmerQuadrant.alpha = this.alpha; }); this.mStage.addChild(mDimmerQuadrant);}Dimmer.prototype.fadeOut = function(){ this.mFadeOut.start();}Dimmer.prototype.fadeIn = function(){}I believe I don't have to post other parts of my code. This is where it all happens.I can have an opacity from 0 to 1. When I ran my code, the opacity is already set to 1. I can't even see my dimmer go into view. This is not the case otherwise. I guess I am missing something critical witw the Graphics actually works under the hood.I appreciate your help! Quote Link to comment Share on other sites More sharing options...
alex_h Posted August 25, 2015 Share Posted August 25, 2015 The alpha properties in your lineStyle and beginFill calls are set to zero, they should not be. The alpha property of the graphics display object is what you are trying to apply the tween to and that is a separate value to the ones used in drawing the vector shape. You should set the lineStyle an beginFill alpha values to 1. neonwarge04 1 Quote Link to comment Share on other sites More sharing options...
neonwarge04 Posted August 26, 2015 Author Share Posted August 26, 2015 @alex_hThanks for your help! You are definitely right. here is my latest code for this one, a little rusty but works for me for now: function Dimmer(stage , screenSize , dimSpeed , color , minOpacity , maxOpacity , enableFadeOut , delayBeforeFade , fadeOutDimSpeed){ this.mStage = stage; this.mScreenSize = screenSize; var mDimmerQuadrant = new PIXI.Graphics(); mDimmerQuadrant.lineStyle(0 , 0x000000 , 0); mDimmerQuadrant.beginFill(color , 1); mDimmerQuadrant.drawRect(0 , 0 , this.mScreenSize.width , this.mScreenSize.height); mDimmerQuadrant.endFill(); mDimmerQuadrant.alpha = minOpacity; this.mFade = new TWEEN.Tween({alpha : mDimmerQuadrant.alpha}) .to({alpha : maxOpacity} , dimSpeed) .onUpdate(function() { mDimmerQuadrant.alpha = this.alpha; }) .onComplete(function() { if(enableFadeOut === true) { new TWEEN.Tween({alpha : mDimmerQuadrant.alpha}) .to({alpha : minOpacity} , fadeOutDimSpeed) .delay(delayBeforeFade) .onUpdate(function() { mDimmerQuadrant.alpha = this.alpha; }).start(); } }); this.mStage.addChild(mDimmerQuadrant);}Dimmer.prototype.setOnComplete = function(callback){ this.mFade.onComplete(callback);}Dimmer.prototype.start = function(){ this.mFade.start();}Thanks! 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.