Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  Graphics2D effects for a newbie  (Read 5509 times)
0 Members and 1 Guest are viewing this topic.
Offline thehodapp

Junior Newbie

« Posted 2012-03-03 00:50:56 »

I'm in an intro game programming class, and I decided to make a game based off a popular game called Geometry Wars in Java2D (professor decided to use it). I'm at a point where I've created a decent game, but with very simple graphics (simple circles, rectangles, solid colors, etc). I have about 0 experience in graphics programming (although quite a bit in other kinds of programming), but I want my game to have a "polished" look.

Specifically I would like to know:

- How to create a glow effect
- Give moving shapes/lines a "trail"
- Do them efficiently

I'm getting a lot of inspiration from this game:
I especially like the explosions and I've implemented a similar effect in my game which basically paints a bunch of white spheres. So for instance, how could I paint them (as efficiently as possible without too much trouble) to both glow and have the cool trail? Of course I would extend the technique to other things in my game.

And thanks for help in advance. Sorry I'm such a newbie, but I'm really enjoying what I've been learning so far.

Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #1 - Posted 2012-03-03 02:03:50 »

Glow effect could be made by drawing a slightly bigger version of the shape with lower alpha so gradually you get a nice gradient fade out at the edges, simulating a glow.

Trail effect is a simple particle system where you just spawn many particles of tiny yellow dots that have a certain direction and lifetime.

This probably won't strain the computer really bad, unless you start getting into ridiculous numbers. Limit the glow effect to 4-5 draws, and a max of 100-200 particles.

Offline ReBirth
« Reply #2 - Posted 2012-03-03 02:55:52 »

With java2d, all you have is play of color, size and alpha without hard blending. So let's be creative.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline thehodapp

Junior Newbie

« Reply #3 - Posted 2012-03-04 03:19:15 »

So I've tried doing the glow idea which works great!...Except I get about 1fps using alpha transparency. Here is a screenshot of the glow effect:

and here's the code:

AffineTransform saveTransform = g2.getTransform();
g2.rotate(Math.atan(PARTICLES[i*2+1]/PARTICLES[i*2]),posX + x, posY + y);

for(int j = 3 ; j > 0; j--) {
   g2.setColor(new Color(0,255,0,50 - j*7));
   g2.setStroke(new BasicStroke(2 + j*7, BasicStroke.CAP_ROUND,
   g2.draw(new Line2D.Double(posX + x, posY + y, posX + x - 7, posY + y));
g2.setStroke(new BasicStroke(2));
g2.draw(new Line2D.Double(posX + x, posY + y, posX + x - 7, posY + y));


please ignore the horribly hacked code; I just wanted something that would work for now....
What can I do about the ridiculously bad frame rates when I use alpha transparency? I am going to need it especially when I add in a background.
Offline ReBirth
« Reply #4 - Posted 2012-03-04 03:49:45 »

Some tips. Use Graphics2D's method to draw line by only passing 4 params so you can avoid an object creation. You created so many object with new instance. Declare all variables on upper side and reuse.

Offline thehodapp

Junior Newbie

« Reply #5 - Posted 2012-03-04 07:45:57 »

I considerably improved performance by first painting the particle to a BufferedImage, then reusing that so each particle doesn't have to keep being rendered. However, I've found what the real problem is:

always returns false. It returns true (after two accesses) when there is no alpha transparency and this goes quite fast. This article says that on all systems except Mac OSX, translucent images are not accelerated by default.  Should I use a VolatileImage instead?
Offline thehodapp

Junior Newbie

« Reply #6 - Posted 2012-03-04 08:14:49 »

Wow. I fixed it. OpenGL apparently wasn't being used on my system. Just passing the flag in this blog made everything super fast.
Pages: [1]
  ignore  |  Print  

hadezbladez (329 views)
2018-11-16 13:46:03

hadezbladez (168 views)
2018-11-16 13:41:33

hadezbladez (327 views)
2018-11-16 13:35:35

hadezbladez (77 views)
2018-11-16 13:32:03

EgonOlsen (2159 views)
2018-06-10 19:43:48

EgonOlsen (2194 views)
2018-06-10 19:43:44

EgonOlsen (1371 views)
2018-06-10 19:43:20

DesertCoockie (1989 views)
2018-05-13 18:23:11

nelsongames (1640 views)
2018-04-24 18:15:36

nelsongames (2289 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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!