Wiki
Clone wikiSpecGine / Intro
Adding intro
Our intro will consist of one slide with image. For purpose of this tutorial we will use our logo.
Getting assets
We start from downloading our logo from here.
This is png file so in most cases you need to right click and select "save as". Move downloaded bitmap into directory android/assets
.
Creating empty slide-show state
Displaying static images during intros in SpecGine is managed by
SlideShowState class.
We place it in file core/src/main/scala/Intro.scala
.
#!scala package com.specdevs.ping import com.specdevs.specgine.states.SlideShowState class Intro extends SlideShowState(nextState = "MainMenu") { def initialize() {} def create() {} def dispose() {} }
SlideShowState
expects us to specify what is the next state to visit after it finishes. We want to jump to "MainMenu"
state after intro,
so this is our nextState
. Now we need to register our new state in game class Ping
from file core/src/main/scala/Ping.scala
.
#!scala def initialize() { addGroup(new Menus, "Menus") addState(new MainMenu, "MainMenu", "Menus") addState(new Intro, "Intro", default=true) }
Please notice that we can add addState
line below other state registrations and still start the game from it if we specify default
option.
Creating slide
What remains is adding new Slide implemented using ImageSlide.
Addjust initialize
method in core/src/main/scala/Intro.scala
to look like:
#!scala //... import com.specdevs.specgine.states.gdx.ImageSlide //... def initialize() { addSlides(new ImageSlide("SpecDevs-logo.png", width=Some(0.5f))) }
We set width of image to half of screen width and its height will be calculated to preserve image aspect ratio. Image will be displayed for 5 seconds (1 second of fade-in, 3 seconds of fully visible image and 1 second of fade-out). Image stopped at any time by clicking mouse, touching touchscreen or pressing any key. There are more options in documentation for ImageSlide.
This all we had to do to see nice intro image at start of our game.
Next we will finally start coding the game itself by adding game state and renderer.
Having troubles with this step?
Here you can download project with all above steps completed.
Updated