Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
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 2155 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: http://www.youtube.com/watch?v=y-_qlaywKBs
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: 345
Projects: 2
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
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,
              BasicStroke.JOIN_ROUND));
   g2.draw(new Line2D.Double(posX + x, posY + y, posX + x - 7, posY + y));
}
g2.setColor(Color.WHITE);
g2.setStroke(new BasicStroke(2));
g2.draw(new Line2D.Double(posX + x, posY + y, posX + x - 7, posY + y));

g2.setTransform(saveTransform);


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:
1  
intermediateImage.getCapabilities(null).isAccelerated();

always returns false. It returns true (after two accesses) when there is no alpha transparency and this goes quite fast. This article http://java.sun.com/products/java-media/2D/perf_graphics.html 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.

http://www.systemparadox.co.uk/node/29
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.

CopyableCougar4 (15 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
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
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!