Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
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  
  MicaByte Game Library: Android 2D framework for games (based on Canvas)  (Read 3441 times)
0 Members and 1 Guest are viewing this topic.
Offline strategy
« Posted 2014-08-05 21:23:38 »

Cool to see that JGO has become relatively active again. Last I was around here, things were looking quite dead.

I know most people roll with OpenGL and 3D for game development, but if there are any here who don't, I released the MicaByte “Game Library” as open-source some time ago. It's available on Github. It's licensed under Apache 2.0.

It's essentially a collection of convenience classes that encapsulates some of the commong functionality that I've found useful while working on my games; an ImageHandler (WeakReference based cache), StringHandler (I do very text heavy games), a very simple MusicHandler, and a fairly complex SurfaceView implementation that handles HUGE images (I've tested up to 10Kx10K pixel bitmaps), and supports scrolling, fling and pinch-zoom on them. There's also the beginnings of renders to support tile maps (both hex and square based).

None of the code is either terrible original, or even very complicated. Most of it is either trivially simple, or stuff I picked up the ideas for around on the web. So I figured that if other can benefit from looking at my code (or even improve it), that alone is worth the effort of cleaning it up and putting it online. Also, I work with open-source for a living, so it's sort of in my DNA these days to just put code out there.

The code base is a bit dirty at the moment, as I've just recently moved things to Android Studio/Gradle and am still refining the libraries, but I plan to clean up the code and the example project in the coming months.

Why Android Canvas?

I work almost entirely in Java Android. That’s mostly a convenience thing – the time I have for game development is very limited, so I try to keep things as simple as possible in my "hobby" work. And say what you will about Android, but it's extremely easy to work with. As I recall, it took me a few weekends to create my first fully functioning Android game back in the day. It doesn't get much simpler than that.

There's another thing that keeps me sticking to Android of course, which is that I hate GUI and graphics programming. I'd just much rather spend my time working on the things that I find interesting: the game design, the game engine and the artificial intelligence. GUI and graphics are the dreary chore that I need to do in order to do justice to the rest. One of the things that I like about the Android framework is that it makes creating and editing flexible GUIs very easy. Very useful, if you - like me - create games with text heavy UIs and lots of tables and options.

Unfortunately, pretty much every game library for Android (and I’ve looked at most) aims for cross-platform compatibility, and in the process essentially end ripping out pretty much everything good about Android. They also tend to focus on full-screen arcade/action game functionality, which tends to be less than useful when you need impart lots of information and display large maps. I played around a bit with libGDX back when it still supported embedding within Android views, but now (or at least last I checked), that functionality is gone (understandable - but unfortunate from the POV of my requirements). If there is something better and easier than native Android for doing simple strategy games in Android, then I certainly haven’t found it yet.

I based it on the Android Canvas, because this was the easiest for me to do at the time. I've looked into re-implementing the 2D functionality using OpenGL a couple of times, but ultimately, the effort just hasn't felt worth it from my POV. as - so far - the performance of the Android Canvas has been sufficient for my needs.

Anyway; posting this here in case this is of use. I enjoy discussing with others who are into developing strategy games/tactical RPGs (which is what I'm using this code for), so if you should happen to find the library useful, do let me know.

Offline gouessej
« Reply #1 - Posted 2014-08-06 09:26:51 »


I remind you that the performance of the Android Canvas isn't consistent across devices. Thank you for your source code, you spent some time in commenting it. However, I still think that you should have used LibGDX, you could have contributed instead of creating yet another engine. I don't want to blame you but creating another engine whereas there are already tons of robust ones already available is counter-productive. Even a few Java based 3D engines with numerous features, a good documentation and tens of examples are used by a very few developers. Good luck.

Offline strategy
« Reply #2 - Posted 2014-08-06 16:50:01 »

I wouldn't insult real game engines by calling this an engine. Wink

It is, as I said, essentially a collection of convenience classes. If others find them useful; I'm happy with that. If not, that's OK too - I developed this for my own use.

Regarding your comments:

- As mentioned, so far the performance of Canvas has been sufficient for my needs. I don't need (or want) to do a lot of animations, and I've never received a complaint about graphical performance.

- I do games with complex GUIs and lots of text; something the Android UI works well for. Every game engine I've looked over so far makes it a pain to integrate with the Android UI (if it is possible at all). Often for good reasons (they want to be cross-platform, or are built for games that don't have complex UI requirements), but it also makes them essentially unsuited for my needs. Last I checked, LibGDX, they consciously made the decision to move away from supporting the Android UI (which I think was a shame, although I understand Marius's reasons for making that choice).

- Since the aims of all these other game engines are not compatible with my aims, I'm pretty sure that none of them miss my meager graphics coding skills.

Of course it is possible that I've overlooked some game engine that makes it a breeze to generate scalable UIs with multiple scrolling views in one layout, drop-down menus, and tons of text labels or can easily be extended to do all that.  Wink But I rather doubt it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2014-08-06 17:17:54 »

Maybe I wrote wasn't clear. It's a shame but the performance of the Android Canvas can be extremely bad on some devices and I understand that you don't need to draw tons of animated sprites but try your game on a very low end Android phone and you'll see what I mean, for example try with an HTC Tattoo. There are similar problems when drawing a rotated bitmap even with the HTC One.

I haven't tested Scene2D (LibGDX) and ardor3d-android could work with ardor3d-ui which supports the basic widget you talk about but it lacks of documentation.

Offline ags1

JGO Ninja

Medals: 62
Projects: 3
Exp: 5 years

Make code not war!

« Reply #4 - Posted 2014-08-06 20:57:53 »

Thanks for making the code available. I have some ideas for games where I might be able to use this.

Can you post some screenshots showing the sort of apps you are building?

Offline strategy
« Reply #5 - Posted 2014-08-07 19:16:39 »

Are you talking about the HTC Tattoo running Donut? Because I haven't seen or heard of one of those in the wild for many years now. But back in the days when it was around, I never had issues with Canvas on that one either. Granted, I hadn't implemented pinch-zoom at the time, but my first phone was the HTC Magic, and I kept that around for quite a while to ensure that it worked.

From my own testing, I'm generally not particularly worried about "weak" phones with small screens; the ones that worry me are the high-resolution devices requiring a ton of pixels to be drawn (and kept in memory, when doing the scrolling maps). But I'll cross that bridge when - or if - I have to.

The two main projects I'm working on at the moment:

The left one is an early draft of Pirates and Traders 2, sequel to my current game. TextViews and Buttons up top; SurfaceView in the center, ImageViews, TextViews and ImageButton at bottom.

The map is a ~6000x4000 pixels piece of art. Location icons and names, ships, and all the other icons are drawn over the Canvas as the game state evolves. P&T was limited to a 1500x1500 base map due to memory issues, but the BitmapRegionDecoder added in SDK10 and a few tricks makes it possible to implement the larger map sizes with - IMO - quite acceptable performance.

In addition to the maps, there are a couple of dozen other in-game views; you can see a few of them on the Facebook page. The character creation/stat/inventory views are probably the most involved, but they're not in a state that I am willing to show anyone yet.  Lips Sealed

The right one is a close to alpha version of a turn-based tactical battle game I'm also developing (I'm developing/testing it as a stand-alone, but the idea is to eventually integrate the game engine into P&T2). The code and art reuse is obvious in the top panel, I assume (I'm not commissioning UI art until the game is almost ready for release).

The bottom UI is a horizontal scroll view that allows the player to browse all their units (each unit "tab" is a couple of imageviews and textviews). One can press the tab to get a toast with more info about the unit, and long press it to replace the scrolling view of the army with detailed unit information of the selected unit (the latter also happens if you select a unit on the map). If the player plots an action, the UI shifts to give the player information about the consequences of that action, and finally if the action results in stuff (e.g., combat), the UI shifts to give information about the result. I'm actually quite proud of this - it's taken quite a while to come up with something here that I feel works well enough to actually work intuitively and provide the player all the information that they might need. I wouldn't have gotten as far with that, if I were trying to build a UI in something requiring more effort than the Android UI SDK does.

The map itself is a Hex tile map, though the current tileset is designed to be seamless, so it's not immediately obvious. Units are overlaid on top (figure by figure), the hitpoints bar is currently just a drawn line on the canvas. Works OK, though it still needs a little improvement. I've not spent a lot of effort on performance yet, so my current implementation in the game GCs way too much.

Pages: [1]
  ignore  |  Print  


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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08 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‑
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!