layout - libGDX: Fade in and out between two Screens without Scene2D -


it's me again :)

i'm trying libgdx game completion. however, have been stuck transitions of 2 screens, want e.g. fade out menu screen when start game , fade in game screen. not use scene2d , not know me stages , actors. glad if me , solve problem.

thanks in advance! :)

don't worry, can achieve aim without using scene2d. anyway, there's more work build building block system it's worth @ end.

concept

the concept have game screen manager manage game screen(s) operating in game. that's being said. when transition 1 screen another, need such game screen manager control game screen able draw, , able update.

normally have such manager manage game screen anyway. can further make use of achieve screen transition effect.

such ability control play major role when transition effect kicks in. fading in/out effect, let's define t total time complete when 1 screen transitions another, a starting screen, b target screen, , m game screen manager, logic behind following

  • fade out a until total time of t/2 has passed, start fade in b. @ beginning when operation starts, m allows a update() own game logic, allow both a , b draw() onto buffer screen. a can update own logic code, both screen can draw.
  • when time duration of t/2 has passed (now in total of t) allow b able update(). means game logic begins take place inside b, , a disposed don't need anymore.

how draw content both a , b during transitioning

you might question how can draw whole content in alpha manner. should mess around customized shader programming? no need. still make use of spritebatch.

the way draw content of such game screen first, draw black texture of size 2x2 pixel (no need make big screen resolution) alpha on top.

such alpha value dynamically calculated mechanism employ in transition effect. use technique, draw content a , b first before drawing black texture on top of both screen alpha value achieve fade in/out transition effect.

more on technical detail

follow guideline of following steps achieve i've described above. i'm not going dwell down detail. these steps idea in implementation not difficult.

  • implement game screen manager control game state, switching between game screen without transitioning effect first
  • implement transitionstate class. class accepts minimally 2 parameters starting game screen, , target game screen (others duration of fading, transitioning effect type, etc) carry out logic explain above in concept , how draw ... section. in short, class game screen (or game state) game, manage 2 game screens @ once when need transition 1 another. can further expand idea include more type of transition effect. transitionstate class building block of screen transition later on. can take , follow along omo tutorial foreignguymike on youtube. can start off start have similar code-base him, or take @ exact episode starting @ 31:08 in starts coding on class. has project file code complete @ episode, can take peek on how implement.
  • whenever need transition current screen another, create new instance of transitionstate feed them starting , target game screen. way tell game switch screen. behind scene, takes time fade out, in, dispose old game screen (which faded out), switch target game screen. continue normally.

that's all. please don't scared lengthy of text input here if core concept, can continue implementing own need understand basic building block of libgdx use it.

good luck on implementation.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -