Ameshi Posted January 21, 2015 Share Posted January 21, 2015 Anyone tried to do this? like use fade in/fade out when changing scenes/maps? I guess I can use a black image and apply alpha values to do the trick? Quote Link to comment Share on other sites More sharing options...
Rick Posted January 21, 2015 Share Posted January 21, 2015 Yes, but draw a rectangle with the context commands instead of an image so you don't require an external resource. 3 Quote Link to comment Share on other sites More sharing options...
xtom Posted January 21, 2015 Share Posted January 21, 2015 Funnily enough I just coded a function for this today... I put the function below in the player script and then use the following to call to run and check it in post render... if self:FadeScreen(0,100) == true then -- screen has now faded to black end if self:FadeScreen(1,100) == true then -- screen has now faded from black end It seems to work pretty good but if anyone spots anything dodge in the code let me know. Still learning lua as I go. -- fades screen to black -- fade 0 fade to black -- fade 1 fade from black -- speed eg. 10=fast 100 slow function Script:FadeScreen(fade,speed) local screenWidth = App.context:GetWidth() local screenHeight = App.context:GetHeight() if fade>0 then -- fade from black if self.fadeValue == nil then self.fadeValue=speed end local alpha = self.fadeValue/speed if alpha<=0 then alpha=0 end App.context:SetBlendMode(Blend.Alpha) App.context:SetColor(Vec4(0,0,0,alpha)) App.context:DrawRect(0,0,screenWidth,screenHeight) if self.fadeValue <= 0 then self.fadeValue = nil return true end self.fadeValue = self.fadeValue-1 else -- fade to black if self.fadeValue == nil then self.fadeValue=1 end local alpha = self.fadeValue/speed if alpha>1 then alpha=1 end App.context:SetBlendMode(Blend.Alpha) App.context:SetColor(Vec4(0,0,0,alpha)) App.context:DrawRect(0,0,screenWidth,screenHeight) if self.fadeValue >= speed then self.fadeValue = nil return true end self.fadeValue = self.fadeValue+1 end return false end 1 Quote Check out my games: One More Day / Halloween Pumpkin Run Link to comment Share on other sites More sharing options...
Rick Posted January 21, 2015 Share Posted January 21, 2015 The only thing, that probably doesn't affect you since you are using a Lua project, would be to get the context via Context:GetCurrent() instead of App.context as C++ projects don't have the App object so the script won't work in a C++ project. By having Context:GetCurrent() to get the context it'll work on both projects. That's obviously detailed but it's something that we all found out early on with scripts in the Workshop after the C++ projects were released in LE (Lua only was the first project type released in LE so everyone just used the App object without understanding the issues with it in C++ projects that would come later on). 1 Quote Link to comment Share on other sites More sharing options...
xtom Posted January 21, 2015 Share Posted January 21, 2015 Ah thanks, I will bear that in mind going forward. Quote Check out my games: One More Day / Halloween Pumpkin Run Link to comment Share on other sites More sharing options...
randomkeyhits Posted January 22, 2015 Share Posted January 22, 2015 This one is on my todo list and I was going to have a go using camera post effects. The simplest idea was to have a straight fade in/out to a specific colour, black or white being the two most obvious. If that worked well I was then going to look at building a small library of shaders for transition effects, fades, page turns, melts, pixellates, all those kind of things. Quote content over form, game play over all. 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.