Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] GameUtils  (Read 2620 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771
« Posted 2014-04-06 14:45:01 »



I present to you a library that I am working on, it is not my main project and it only gets developed along side.
The idea behind this library is to create an abstract as possible set of utilities that can be used in most LibGDX games

Intro Video

<a href="http://www.youtube.com/v/kEwN6oCeGQI?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/kEwN6oCeGQI?version=3&amp;hl=en_US&amp;start=</a>




What GameUtils Can Currently Do

So far I have implemented a few things that I needed to make my game code look a bit neater and less clunky, although nothing major has been added at the moment I intend to add whatever I feel can be reused for pretty much any game

Current Features:

* Stuff in Italic are in the process of being developed *

    Camera:

    Further expanding the features of LibGDX Cameras

    • ActionOrthographicCamera- Easily follow given Vectors with 1 line clean code and/or give your camera a rumble effect. This camera will be developed with fast paced action games in mind

    Box2D:

    Things to make your life with Box2D just that little bit easier.

    • Box2DObject - Create a Box2D object by calling easy to read methods
    • Box2DFactory - Easily and safely remove Box2D bodies/fixtures/joint swith 1 line of code

    Time:

    A bunch of time related classes, such as a Stopwatch or Virtual clock!

    • Timer - A simple timer that increases the counter until you say otherwise, can trigger a callback to get your game to do something upon stopping!
    • Stopwatch - Create a stopwatch that counts down from a set time, then have it trigger a custom event
    • Clock - Simulate a clock in your virtual world, trigger events depending on time or slow the passage of time!

    Event

    A way for you to manage events, trigger them with 1 line of code anywhere in your code or trigger them with time

    • Event - Create custom Events for your game with an easy to implement system
    • EventHandler - Trigger your Events with 1 line of code, give the EventHandler a clock and it will trigger your Events at given times

    AI

    • State - Create custom states for your game in-game entites/objects with a simple implementation
    • StateMachine - A simple way to update and keep track of your states, create states and simply call easy to read methods to move between them

    The Future of GameUtils

    I will be working on/adding features to this library over the course of my work, which at the moment looks like a fair bit of time. In the future I look to have a library that works as a mini addon engine that can easily be used with most LibGDX projects.

    This will not be some half assed attempt at making something that has half functionality, it will be as clean as possible, with easy to read code and a heavily documented source and Wiki.
     

    How You Can Help Me

    If you like the sound of this and find a use for it, even it is a small use (I personally think the camera rumble is awesome yet it's so simple), please comment here. If you have ideas feel free to let me know! If I have time to implement them I will, if you have issues you can report them on the issue tracker on BitBucket, if you follow/watch my repo that will give me a great boost!


    Downloads/Links

    [/list]

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline wessles

    JGO Wizard


    Medals: 67
    Projects: 4
    Exp: 3 years


    Profile picture isn't relevant.


    « Reply #1 - Posted 2014-04-06 15:35:10 »

    I absolutely adore these kinds of projects. I am glad you are working on this! I always like projects that are made so that other projects can easily integrate into libraries, engines, tools, etc. It is a great thing to do for the community, as it cuts development time in half.

    Good on you,
    -wes  Smiley

    Offline Slyth2727
    « Reply #2 - Posted 2014-04-06 16:00:05 »

    I made one of these for jME a while back and am porting it over to LWJGL for my engine. Have fun, it's a good project Smiley

    Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
    Games published by our own members! Check 'em out!
    Legends of Yore - The Casual Retro Roguelike
    Offline Gibbo3771
    « Reply #3 - Posted 2014-04-06 18:01:50 »

    I absolutely adore these kinds of projects. I am glad you are working on this! I always like projects that are made so that other projects can easily integrate into libraries, engines, tools, etc. It is a great thing to do for the community, as it cuts development time in half.

    Good on you,
    -wes  Smiley

    Thanks for the support! Yeah I have made like 4-5 games using a mixture of LibGDX/Box2D and I find myself re-creating the same system for deleting bodies and stuff, as well as a lot of other useless repetitive code.

    No longer shall I suffer Cheesy

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline Gibbo3771
    « Reply #4 - Posted 2014-04-08 19:31:06 »

    Small update, added some coolish features:

    New:

    • Stopwatch - Countdown to 0 and then trigger a custom event
    • Clock - Simulate a virtual clock in your game, trigger events depending on time, become part of the matrix and manipulate time (adjust clock pace)

    Changes

    • Box2DFactory
      • Delete Bodies
      • Delete Fixtures
      • Delete Joints

    Hopefully someone can find the use for some of this stuff, I intend to add a clock to my game, for the looks more than anything else. I intend to add "Bullet time" so it would be cool to see the clock slow down with it, I will probably use the Stopwatch much like a timer, say for a bomb or a level time.

    I do not think these are coded in the most effective way, I will probably take a look at creating an EventManager that will work along side the clock and other things but for now this basic system is sufficient for what I need.

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline actual

    JGO Coder


    Medals: 23



    « Reply #5 - Posted 2014-04-09 05:26:31 »

    A couple of random minor comments about StopWatch:

    Is there a reason why the callback is implemented as a StopWatchCallback interface as opposed to a simpler no argument interface like execute()? I could see using this to schedule command pattern style code where I don't really care about the timer, I just want to do something when it goes off. Also, I may want to use my command object outside of the StopWatch and now I need to either pass in null to the execute or have a separate no-argument execute method.

    It might be nice to have a setCallback(StopWatchCallback callback). Depending on what is going on in a game one may wish to change the callback while the stopwatch is counting down.

    You may want to have more states for your StopWatch (start, stop, pause, resume). You could even assign different callbacks to each in case you wanted it to respond differently to it pausing vs. stopping prematurely.

    EDIT:
    Another random thought. Are or should StopWatches be associated with a Clock and if so, would the StopWatch count down at a rate equal to the Clock rate, so that if the Clock slows down, the StopWatch does as well?
    Offline Gibbo3771
    « Reply #6 - Posted 2014-04-09 05:49:17 »

    A couple of random minor comments about StopWatch:

    Is there a reason why the callback is implemented as a StopWatchCallback interface as opposed to a simpler no argument interface like execute()? I could see using this to schedule command pattern style code where I don't really care about the timer, I just want to do something when it goes off. Also, I may want to use my command object outside of the StopWatch and now I need to either pass in null to the execute or have a separate no-argument execute method.

    It might be nice to have a setCallback(StopWatchCallback callback). Depending on what is going on in a game one may wish to change the callback while the stopwatch is counting down.

    You may want to have more states for your StopWatch (start, stop, pause, resume). You could even assign different callbacks to each in case you wanted it to respond differently to it pausing vs. stopping prematurely.

    EDIT:
    Another random thought. Are or should StopWatches be associated with a Clock and if so, would the StopWatch count down at a rate equal to the Clock rate, so that if the Clock slows down, the StopWatch does as well?

    Thanks for the input, I'll go through them in order.

    Hm yeah now that I think about it the method does not need to have any arguments. The design was slightly different when I first started, I'll fix that.

    Good idea, never considered that.

    Easily done and make sense, currently stop pauses it which actually makes no sense at all.

    As it stands the now, the stopwatch is set to timeFactor = 1 by default.

    milliseconds -= ((1000 / 60) * timeFactor) + (delta * fps)

    If you want to keep the update speed the same for a clock and a stopwatch, you can use a variable and pass it to asjustTimeFactor(double timeFactor); for both instances.

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline actual

    JGO Coder


    Medals: 23



    « Reply #7 - Posted 2014-04-09 10:48:06 »

    Looks good...I've been thinking about timers, intervals, etc a fair bit recently which is why these thoughts are coming to me. As for the last point, it might be nice to have a constructor for StopWatch that takes a Clock as a parameter. That way when you slow or speed up the clock time, the stop watches speed or slow down automatically.
    Offline Gibbo3771
    « Reply #8 - Posted 2014-04-09 11:15:37 »

    Looks good...I've been thinking about timers, intervals, etc a fair bit recently which is why these thoughts are coming to me. As for the last point, it might be nice to have a constructor for StopWatch that takes a Clock as a parameter. That way when you slow or speed up the clock time, the stop watches speed or slow down automatically.

    Hm, that bit I am not sure about, that might be a bit too specific. The Clock and Stopwatch might share a similar superclass and are a type of GameTimer, however they are completely separate tools. Trying to integrate them together like that might make it look messy imo.

    Or not?

    Btw I implemented what you recommended, you can now set the callback manually, you can start, pause, resume and stop the stopwatch as normal or pass a new callback, like so:

    1  
    2  
    3  
    4  
    5  
    6  
    7  
    8  
    9  
    10  
    11  
    12  
    13  
    14  
    15  
    16  
    17  
    18  
    19  
       /**
        * Simply pause the stopwatch, this ceases all updates until you call
        * <code>resume()</code>
        */

       public void pause() {
          started = false;
       }

       /**
        * Simply pause the stopwatch, this ceases all updates until you call
        * <code>resume()</code>
        *
        * @param stopwatchCallback
        *            the new callback
        */

       public void pause(StopwatchCallback stopwatchCallback) {
          setStopwatchCallback(stopwatchCallback);
          pause();
       }


    I also implemented a bit of error trapping and a reset method, you can not reset a stopwatch while it is running, you can not start a stopwatch that is set to 00:00:00:00. Small little things to stop the user from experience weird outcomes.

    I also made it so that when you stop the stopwatch, it automatically does the callback. Also a stopped stopwatch will no longer do anything if stop is called again.

    I also implemented a way to reset it back to the values it was before you started it:

    1  
    2  
    3  
    4  
    5  
    6  
    7  
       public void reset() throws GameUtilException {
          if (started)
             throw new GameUtilException(
                   "You can not reset a running stopwatch, stop() must be called first!");
          currentTotal = 0;
          setTime(resetTime[0], resetTime[1], resetTime[2]);
       }


    The resetTime[] array is adjusted everytime the user calls setTime, makes it a little easier to default back.

    What ya think? Full source will be up in an hour or so.

    Let me know if you spot anything or have any other ideas.

    I am also going to create a similar Timer, except it counts up...like a timer lol, Then does a callback, simple to implement but imo highly useful.

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline saucymeatman
    « Reply #9 - Posted 2014-04-10 01:06:09 »

    This is a good idea, very usefull Smiley
    Ill definetly use this timing stuff, all of it is great

    (Taken from the stopwatch docs)
    Quote
    I will go ahead and set the time of my stopwatch to 10 seconds:
    1  
    stopwatch.setTime(0, 0, 5);

    That confused the hell out of me.
    Games published by our own members! Check 'em out!
    Legends of Yore - The Casual Retro Roguelike
    Offline Gibbo3771
    « Reply #10 - Posted 2014-04-10 06:55:47 »

    This is a good idea, very usefull Smiley
    Ill definetly use this timing stuff, all of it is great

    (Taken from the stopwatch docs)
    Quote
    I will go ahead and set the time of my stopwatch to 10 seconds:
    1  
    stopwatch.setTime(0, 0, 5);

    That confused the hell out of me.

    AW f**k lol.

    I've been spending 8 hours a day on this for 3 days, I get tunnel vision lol

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline Gibbo3771
    « Reply #11 - Posted 2014-04-12 13:44:11 »

    Hi guys, I have a sort of decent update for you all to have a gander at.

    Added:

    • Events
    • EventHandler

    Fixes:

    Fixed a bunch of stuff, removed the clocks 12 hour capabilities, it needs rethought. Simple to fix, just a pain and it was getting on my nerves.

    Added stop and pause method to the Clock.

    I hope someone finds a use for some of this stuff lol, I spent a while trying to make the thing as fool proof as possible, it should be almost impossible to mess up your logic as I have added quite a lot of error trapping.

    I am in the process of creating videos for my "final" classes, as in the ones that are at there fullest and probably won't be altered much in the future, besides improvements, for instance I will probably remove the GameTimerCallback for the Stopwatch and just have it take an Event instead.

    If you have any ideas let me know!

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline moe091

    Innocent Bystander





    « Reply #12 - Posted 2014-04-12 15:52:14 »

    Awesome project! I'm going to try and work this into my current libgdx project as soon as i get home. Are you working on this solo or would you mind having another contributer to the project? If there are any features you want but don't have the time to add I'd be happy to donate some time, I'd keep everything I write very clean and document as I go.

    I'm currently working on a level editor for box2d/libgdx right now and I could definitely benefit from using your gameUtils. I just joined java-gaming I plan on sharing my level editor with everyone once I get a littler further into it, I'll also release the small gui library I'm developing for use with it.

    Good luck with the project I can't wait to try it out!
    Offline Gibbo3771
    « Reply #13 - Posted 2014-04-12 16:33:57 »

    Awesome project! I'm going to try and work this into my current libgdx project as soon as i get home. Are you working on this solo or would you mind having another contributer to the project? If there are any features you want but don't have the time to add I'd be happy to donate some time, I'd keep everything I write very clean and document as I go.

    I'm currently working on a level editor for box2d/libgdx right now and I could definitely benefit from using your gameUtils. I just joined java-gaming I plan on sharing my level editor with everyone once I get a littler further into it, I'll also release the small gui library I'm developing for use with it.

    Good luck with the project I can't wait to try it out!

    Thanks for the reply and support!

    I am currently working on this solo, I am not looking for someone to contribute to it directly however you are more than welcome to create using what I got, or take what I got and edit/optimize it for yourself, then you are free to use/distribute it under the conditions I am credited.

    I would not rely on it too much for your project, I am in the process of properly refactoring it, a lot of code is repeated, such as in Clock and Stopwatch, they have same fields but extend from the same class.

    Small things, really.

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Offline Gibbo3771
    « Reply #14 - Posted 2014-04-14 13:47:47 »

    Hi guys, I do have some things in the development pipeline, I have started putting some spare time into a StateMachine that can be used for any object.

    I have refactored the Stopwatch and Clock quite significantly, they now share a fair bit of base code from the GameTimer class, as they should.

    Other than that I have just been changing up javadoc to reflect the refactoring and spelling mistakes!

    However I have done something useful...

    I started making some video tutorials on how to use the basics, because I am absolutely terrible at writing up Wikis Sad.

    You can find them on the Wiki Page of the respected class, so far I have done the ActionOrthoCamera, Stopwatch, Box2DObject and Box2DFactory. They are fairly simple to use but I felt like it would help towards my goal of having a properly documented library!

    Enjoy, hope my accent is understandable lol!

    "This code works flawlessly first time and exactly how I wanted it"
    Said no programmer ever
    Pages: [1]
      ignore  |  Print  
     
     
    You cannot reply to this message, because it is very, very old.

     

    Add your game by posting it in the WIP section,
    or publish it in Showcase.

    The first screenshot will be displayed as a thumbnail.

    Longarmx (52 views)
    2014-10-17 03:59:02

    Norakomi (43 views)
    2014-10-16 15:22:06

    Norakomi (33 views)
    2014-10-16 15:20:20

    lcass (37 views)
    2014-10-15 16:18:58

    TehJavaDev (68 views)
    2014-10-14 00:39:48

    TehJavaDev (66 views)
    2014-10-14 00:35:47

    TehJavaDev (59 views)
    2014-10-14 00:32:37

    BurntPizza (73 views)
    2014-10-11 23:24:42

    BurntPizza (45 views)
    2014-10-11 23:10:45

    BurntPizza (86 views)
    2014-10-11 22:30:10
    Understanding relations between setOrigin, setScale and setPosition in libGdx
    by mbabuskov
    2014-10-09 22:35:00

    Definite guide to supporting multiple device resolutions on Android (2014)
    by mbabuskov
    2014-10-02 22:36:02

    List of Learning Resources
    by Longor1996
    2014-08-16 10:40:00

    List of Learning Resources
    by SilverTiger
    2014-08-05 19:33:27

    Resources for WIP games
    by CogWheelz
    2014-08-01 16:20:17

    Resources for WIP games
    by CogWheelz
    2014-08-01 16:19:50

    List of Learning Resources
    by SilverTiger
    2014-07-31 16:29:50

    List of Learning Resources
    by SilverTiger
    2014-07-31 16:26:06
    java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
    Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!