Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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  
  Game Screen "Shake" and Gradient Paint in a Directed Cone  (Read 1615 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-02-24 23:52:34 »

Alright, I have two questions and I didn't want to clog up the forums with topics, so I thought I'd put them in a single post.

1.Making a Game Screen "Shake"

Right, so in the game "Droid Assault" which I was introduced to by these forums, sometimes, when you do some electricity thing, the game screen kind of shakes back and forth. At first I thought, "Hey all they did was take the game, pause it, take the current screen and put it into a buffered image and do some jiggery hokery with sin and such... But I am not quite sure now. Does anybody know how to achieve this?

2. Making a cone with a gradient

Again with Droid Assault, I saw the lights that follow the player and fade from red to transparent in a conical shape. I thought they may have used gradient paint, but I am not experienced with that at and after some research I still could not think of a way. As you can probably see I am a little bit of a novice. Suggestions? Thanks -cMp

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Online HeroesGraveDev

JGO Kernel


Medals: 246
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-02-25 04:34:04 »

1. Many ways you can do this. Probably the easiest is translating by a vector whic is in turn moving in random directions.

2. Shaders.

Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2013-02-25 11:19:28 »

I simply translate the modelview matrix by a random amount before drawing the game:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
void render() {
   float yOffset = 0.0f;
   if (shakeTick > 0) {
      shakeTick--;
      yOffset += Util.random(-shakeTick, shakeTick);
   }
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef(0.0f, yOffset, depth);
   
   // draw everything else
}


The cones of light are just big sprites.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Slyth2727
« Reply #3 - Posted 2013-02-25 12:48:41 »

Dang sorry guys, I meant to say I am just using the Java Graphics library. Sorry bout the miscommunication. Any ways to do this in plain java?

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline Longor1996
« Reply #4 - Posted 2013-02-25 13:13:13 »

How about:
1  
2  
3  
4  
5  
6  
7  
8  
9  
//You untranslated Graphics object.
Graphics g = ...;

if(shakeTick > 0){
   shakeTick -= delta;
   g.translate(/*random values*/);
}

//Draw everything else...


This could work.
Im always using OpenGL since it's easier to do graphical effects with it.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2013-02-25 13:51:44 »

That'd work.

Cas Smiley

Offline Slyth2727
« Reply #6 - Posted 2013-02-25 21:11:30 »

Works great! I dont know why I didnt think of that before... And when you say the cones of light are big sprites, I automatically think, "Rotation? How?!?!?". I have used (Graphics2D Object).setTransform() before, but I really really dislike it because it confuses me a ton. Is there a way to avoid this and just use something else? Thanks cMp

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline StumpyStrust
« Reply #7 - Posted 2013-02-25 21:16:48 »

Java2d rotation is silly easy.

1  
2  
Graphics2D g2d = (Graphics2D)g.create();
g2d.setTransform(AffineTransform.getRotateInstance(rotation.x, loc.x, loc.y));


rotation.x is your rotation in degrees 0-360

loc.x and loc.y are your coordinates on the screen.

Do this before drawing.

Make sure to call g.dispose() when you are done drawing.

Offline Slyth2727
« Reply #8 - Posted 2013-02-25 21:28:05 »

Well I have seen that, but is the x and y coordinates the x and y you are giving to g2d.drawImage(), or is it the anchor coordinate, or something else?

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline jonjava
« Reply #9 - Posted 2013-02-25 23:36:06 »



http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/geom/AffineTransform.html

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StumpyStrust
« Reply #10 - Posted 2013-02-26 01:49:39 »

It depends on how you want to rotate. In most cases it will be the center point of your sprite. If you draw with the starting point being in the top left corner, then you need to add half your sprites width to the x and half of the sprites height to the y.

Offline Slyth2727
« Reply #11 - Posted 2013-02-26 02:43:14 »

Alright, I think I have it all working! I'm gonna update my post with my game in it soon with some great improvements and new features Cheesy

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

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

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

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

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

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

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

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

BurntPizza (49 views)
2014-08-09 21:09:32
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!