The last couple of days and weeks I've been working for some kind of project just for having fun with coding and creating something which is somehow intresting.

It's a resource loader, which can load image sprite sheets and provide cut-out Images after those are loaded. Additionally it allows specifying filters, operating in multiple layers when using filters, etc.

What those do is pretty simple to explain:In the <animation> tag come the <frame />s. Those frames specify the rectangles for each frame inside the "bounds" tag. the "name" attribute from the animation tag is a name for the animation, which makes it possible to be referenced from the program.I won't explain those in great detail. They were the main part of the project at first, but now something else is much more intresting

The <filters></filters>:

I will try to explain those with an example.

We have the source image from above using the same frames and animation as in the xml.

Now what we want is, we want to colorize the image. But only the parts which are grayscale. Additionally we remove the white, opaque pixels in the image and make them white, but transparent. We can do this using two filters:

Now this animation would be generated (scaled 8x and my application cannot export gif with transparency...):

This is an image which one could use in a game already. But to show you even more advanced filter combinations, and play around a little, and finally also show you how to copy kevglass's voxelization effect (see this thread ), I'll use the "voxelization" filter / effect:It subtracts the color in a specified grid by a specified ammount:

We also scale the image at first to make it possible to create borders around each pixel. Otherwise we couldn't make 4x4 pixel voxels.The result is this animation:

And since this is not enough. Not even to show all features, I want to 'clone' the Realm of the mad god sprite effects:

As you can see, realm of the mad god sprites have a black outline and a slight black blurred shadowed outline around the characters.I can recreate this using filters.

First, let's do the black outline. For that I use my 'outline' filter. It creates an outline, which is exactly one pixel wide. We also scale the image again twice, to make the outline a little more subtle:

Now we have two problems: How do we add a blurred shadow, and how do we make the sprite bigger, so the shadow (and the outline, too) have place to exist around the sprite?

Well, the solution for the size: expand filter. It adds an empty border to the sprite. I might rename it into 'border' and add some more functionality...(I won't give an example image here, the result should be clear)

The solution for the shadow is a bit more complicated. For that I use something I call 'branch'.

It works like that:As soon as my parser encounters a <branch> tag, it saves the old image and proceeds operating on a copy of it. At the end those images are merged together by the specified branch merge operation.

So thats it with the demonstration.I won't release a demo / the source code yet, since it's not finished. The blur filter is much too inefficient. Still have to optimize it.

I don't think this might be too useful to you. This was more of a project just 4 fun, and probably for the use in some of my games, but it's written in scala, so I guess nobody will want to read the project's source, nor use it, since it's not too nice to use from java

Hehe, had to write my own for last posted wip, had a weird deja vu when I saw this X)I think the idea of adding filters and properties through the XML is really cool though; also the shadow is looking awesomes!Considering porting it to Java as a library? :3 /glee

@Danny I think Apex talked about it not being useable really nicely from the side of java. Something like you'd have to write method$less$greater method names, but the library actually works well, if you don't want to write your own filters ^^. But you have to write your own backend if you want to use it with OpenGL (that is: LWJGL) or LibGDX or similar, but that should be trivial 2 classes.

defregion(name: String) = regions.get(name) match {caseSome(region) => regioncaseNone => thrownewIllegalArgumentException("There is no region available for the name \""+name+"\"") }defanimation(name: String) = animations.get(name) match {caseSome(anim) => animcaseNone => thrownewIllegalArgumentException("There is no animation available for the name \""+name+"\"") }

defallAnimations = animationsdefallRegions = regions

defload(loadingSource: L, directory: File)}

Also, to make some updates, I've made the library reasonable fast. It has now an implementation for my so-called 'native filters'. These are filters the implementation / backend implement. So you could implement a blurring algorithm running with shaders on the gpu, instead of the CPU. That's almost how I implemented a faster blur algorithm. The blur doesn't take 1600 ms for a 80x80, but actually only takes 4 ms. This was quite a satisfying number

defregion(name: String) : I = regions.getOrElse(name, thrownewIllegalArgumentException(s"There is no region available for the name \"$name\"") )

I also threw in a string interpolation for free

Oh yes, I know... I've used it later in my learning progress, this was the first (or second) class I made in this project, when I almost didn't know scala... Didn't know the string interpolation though... (strange name)

To provide a further update:It's now possible to define groups of filters:

Actually a for-comprehension over Either would be ideal for this but Scala's Either is kind of broken as a monad. Scalaz has a Validation type that's pretty nifty though, you just have to deal with Scalaz's general lack of documentation

Yep. Already seen Scalaz. Pretty sure I'll use it Head of it having state-monads implemented. I really think this is an awesome piece of science.The problem I have with those is only that they're not really needed in a non-pure-functional language. And it's sad that JVM can't handle pure functionality.

The code is probably not readable at all... Well, if you put some time into it. But the most ugly class is 'org.matheusdev.animationSwing.AnimationTester', which is the test class for viewing animations and exporting them to .gif's. It's incredibly ugly.Yes. It's a single file.

Also, have a look at the other classes inside 'org.matheusdev.animationSwing' (SwingImge, SwingImageLoader), to see how easy it is to write backends for my lib

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