2D Drawing

I’m trying to figure out what the best way to draw a 2d game is, and I’m pretty much stumped.

I use a StrategyBuffer in a canvas at the moment, and this is basically what I’m doing right now:

Updating method: http://pastebin.com/zrmmTGEg
Drawing method: http://pastebin.com/924nhQkp
Image2D.java: http://pastebin.com/T16CrRq2

Educate me. ;D

LibGDX

It’s a game-centric library, includes tons of tools and documentation, distributes to many platforms, and is built on OpenGL as to ensure high rendering performance.

Thanks, but I was looking for more of an alternative that wouldn’t include using libraries that weren’t made by myself.
Although- It does look interesting so I will definitely check it out and give it a go! :slight_smile:

The reason why I’m looking for an alternative that doesn’t use a library; is because I’ve got this thing where I don’t feel as accomplished if I didn’t make 100% of it.

Then try lwjgl. I am sure davedes will post his great tutorials on it. :wink:

If you don’t like the idea of using libs then why are you using any of the built in java libs?

Haha you got me there, what I meant specifically were libraries other than the stock ones. :stuck_out_tongue:

If you are ok with inconstant performance and many missing features that really are very nice to have for game dev then you can use java2d but I strongly recommend opengl.

Basically, fastest way of rendering an image in java2d is simply graphics.drawImage(image stuff);

Use bufferedimages. Don’t worry about the whole volatile image thing as it does very little for you unless you are trying some hacks.

g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) (fade)));
        g2d.setTransform(AffineTransform.getRotateInstance(rotation.x, loc.x, loc.y));

That is the fastest way I found for rotating and changing alpha for images.

Sounds like you have a case of NIH… (Not Invented Here).

Honestly, you’d be foolish not to use LibGDX. Just because it’s a third-party library doesn’t mean you should shy away from it (Java2D and LWJGL are also third-party libraries). If you want to avoid third-party code at all costs, you should be writing your own rasterizer in C and assembly. ::slight_smile:

For example, here are three scenarios, and in all cases LibGDX is the best choice:

  1. You want to make a game. Without LibGDX, you have a lot of boilerplate to write (game loop, texture handlers, shader compilation, tiled map loader, etc). LibGDX makes development smoother and allows you to focus on programming the game itself.

  2. You want to learn general graphics programming. LibGDX gives you a high-level platform for manipulating GL, textures, shaders, and so forth without wasting time tinkering with hundreds of lines of OpenGL boilerplate. It’s an easier way to learn the pipeline.

  3. You want to learn OpenGL from the lowest level. At this point some people may suggest LWJGL, but really LibGDX is just another OpenGL wrapper at its core. So you can get down to the nitty-gritty and write your own texture loaders, if you really want to reinvent the wheel. The difference is, you’re working with a cross-platform solution (LibGDX ports to iOS, WebGL, Android, and Desktop) as opposed to LWJGL, a desktop-only solution. And, with LibGDX, you have the option to use its utilities (shaders, asset management, image decoders, 3D model loaders, JNI-accelerated matrix math) whenever you want.

If I still haven’t convinced you… and you refuse to use LibGDX, start poking around my tutorials and code here (which is just “straight LWJGL”).

After checking LibGDX’s Wiki, I’ve decided to move on from tinkering with my ‘while (running)’ statement and spamming draw().
I’m comfortable and confident with saying I think this is going to go well. :slight_smile:

You’ve all helped convinced me, I really appreciate it. ;D

I wonder how many people you’ve converted to libgdx over the years…

Not enough. ;D

Being a sufferer of NIH all I can say is… Check the Java4k games, study their code, some have pretty neat tricks you can learn from.

Still, making stuff on your own without third-party is justifiable. A couple reasons off the top of my head:

  • Educational purposes: If you want to know how pure Java ticks and what its limitations are.
  • Platform Limitations: Maybe you’re developing a Java4k game, maybe for a mobile device with pure java exclusively, or maybe for a platform where alternative libraries don’t work correctly.

Or, maybe, you’re just a masochist like I am… ::slight_smile:

Assembly and C involve 3rd party code. Type the .bin files out by hand. :wink:

Anyway, NIH is not neccessarily a bad thing. You have to realise your limits and not go about creating a new operating system just to make a game.

There is also a good reason for NIH:

The more “easy-to-use libraries” out there, the more n00bs you get asking stupid questions about things that would be obvious had they learnt how things really work.

The main reason why I don’t like using third party libraries is because I like to know how everything works.

For example; I’ve always wanted to create my own really basic 3D rendering. Similar to what RuneScape used back in 2003-2006. (Software Rendering)
But their client’s rendering is so obfuscated that I couldn’t learn from it.

It’s not actually hard to make your own software 3D rasterizers. I’ve made quite a few about 10 years ago. I hope you can read quickbasic…(Scroll down for the 3D series.)

http://rel.phatcode.net/index.php?action=contents&item=Tutorials

I also have an x86(fixed point integer) assembly version of the rasterizer if you want.

But really, in this day and age, you’d better be learning OpenGL.

After using libGDX, I’ve determined that it just isn’t for me, instead I’ll be checking out Relminator’s link and just learning to create my own 3D rasterizer.

Thanks everybody for your input! :slight_smile:

???

When I said writing your own rasterizer, I meant it as a joke. It will lead to pretty terrible performance compared to LibGDX and you will be nowhere closer to making a 2D game. Can I ask why you didn’t like the library and/or how you feel it could be improved?

Just curious. :wink:

LibGDX may have an upper hand on performance, but that doesn’t necessarily mean the rasterizer would be bad. :slight_smile:

I didn’t enjoy using the library because I feel like I should be learning how to create my own tools and use those tools to make my own content.

I’ve got a severe case of NIH and so far nothing has cured me of it. :frowning:

Edit: Actually, I’m thinking of using either LWJGL or some basic wrapper for OpenGL.

I know LibGDX is derived from LWJGL but it’s just the way LibGDX is setup that I don’t like very much.