Advertisement
dermetfan

decription of Java Game Development (LibGDX) | Request 3

May 26th, 2013
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. http://youtube.com/LegitzDestroy asked for a way to memorize the concepts. In my opinion, a good way to do this is to remember the order of things you have to do to create a new Screen from scratch.
  2.  
  3. Short summary:
  4. 1: create class that implements Screen 00:58
  5. 2: create fields that you'll need: Stage, Skin 01:25
  6. 3: make sure to dispose everything in dispose() 04:38
  7. 4: make sure dispose() is called by putting it in hide() 05:43
  8. 5: clear the screen, update and render the stage in render() 06:14
  9. 6: resize the stage and optionally other things in resize() 07:39
  10. 5: set them in the show() method, basically create the menu there 09:45
  11. 5.1: stage = new Stage();
  12. 5.2: don't forget Gdx.input.setInputProcessor(stage);
  13. 5.2: skin = new Skin(Gdx.files.internal("ui/skinFile.json"), new TextureAtlas("ui/atlas.pack"));
  14. 5.3: create all the Actors you want
  15. 5.4: put actors in each other (e.g. buttons in table, table in stage)
  16. 5.5: put actors in the stage
  17.  
  18. Or like this:
  19. --------------------
  20. public class Concepts implements Screen {
  21.  
  22.     // 1. setup variables
  23.     private Stage stage;
  24.     private Skin skin;
  25.    
  26.     // 2. create objects
  27.     @Override
  28.     public void show() {
  29.         stage = new Stage();
  30.         skin = new Skin(Gdx.files.internal("ui/creditsSkin.json"), new TextureAtlas("ui/atlas.pack"));
  31.     }
  32.    
  33.     // 3. dispose stuff
  34.     @Override
  35.     public void dispose() {
  36.         stage.dispose();
  37.         skin.dispose();
  38.     }
  39.    
  40.     // 4. actually dispose
  41.     @Override
  42.     public void hide() {
  43.         dispose();
  44.     }
  45.    
  46.     // 5. render
  47.     @Override
  48.     public void render(float delta) {
  49.         // 5.1 clear screen
  50.         Gdx.gl.glClearColor(0, 0, 0, 1);
  51.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  52.        
  53.         // 5.2 update
  54.         stage.act(delta);
  55.        
  56.         // 5.3 draw
  57.         stage.draw();
  58.     }
  59.  
  60.     // 6. resize if needed
  61.     @Override
  62.     public void resize(int width, int height) {
  63.         stage.setViewport(width, height, false);
  64.     }
  65.  
  66.     @Override
  67.     public void pause() {
  68.     }
  69.  
  70.     @Override
  71.     public void resume() {
  72.     }
  73.  
  74. }
  75.  
  76. --------------------
  77.  
  78. Concept for the TweenEngine:
  79. 1. write Accessors (implementing TweenAccessor<Class>):
  80.  - make a switch statement that takes tweenType
  81.  - set returnValues to values of target / set attributes of target with newValues
  82. 2. create a TweenManager
  83.  - tweenManger = new TweenManager(); // as simple as that
  84.  - update it in render method: tweenManager.update(delta); // simple again
  85. 3. register TweenAccessors:
  86.  - e.g. Tween.registerAccessor(Actor.class, new ActorAccessor());
  87. 4. create animations:
  88.  - Tween.to(buttonPlay, ActorAccessor.ALPHA, 2).target(1).start(tweenManager); // alpha transparency goes to 1 in 2 seconds
  89.  - Tween.from(buttonPlay, ActorAccessor.ALPHA, 2).target(0)).start(tweenManager); // alpha transpareny comes from 0 to what is has been before in 2 seconds
  90. 5. you can create Timelines:
  91.  - Timeline.create[Sequence/Parallel]().begin[Sequence/Parallel]().push(animation).push(infinite_more_animations).end().start(tweenManager);
  92.  
  93. --------------------
  94.  
  95. Sorry for no uploads in a long time. If you want to know about the current progress, you can have a look at https://trello.com/b/Y3az2rtU/development.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement