Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (622) 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
 Clipping  (Read 2579 times) 0 Members and 1 Guest are viewing this topic.
Pyrodragoon

Junior Devvie

Art calculated with java...

 « Posted 2008-03-26 23:12:53 »

Hi again.
With Java2D there is the possibility to just draw a part of the screen, f.e. an oval by using

graphics.setClip(shape);

What I need now is something that does clipping to the rest of the screen.
Something like an setContraClip(shape);
which leaves the shape out and only draws to other parts of the screen.

Is this possible with Java2D or does anyone know a simple solution to implement
this myself?
Eatserbeam

Junior Newbie

 « Reply #1 - Posted 2008-03-30 16:12:18 »

I hope this help you

[url removed]

is all about 2d graphics  clipping, grandients, tiles, textures, fonts, graphics, shapes, all 2d graphics examples

Don't link copyrighted material, please. / Markus
Pyrodragoon

Junior Devvie

Art calculated with java...

 « Reply #2 - Posted 2008-03-30 18:46:08 »

Big THANKS for this one.
I hope I find the answer in there, if not it might not exist.
This is an awesome pdf about Graphics2D.
I post again when I find the answer.
 Games published by our own members! Check 'em out!
Pyrodragoon

Junior Devvie

Art calculated with java...

 « Reply #3 - Posted 2008-05-12 21:26:30 »

So here´s the answer:

there is something called Area in java which
can add or subtract Shapes.

So it would look like this:

Graphics2D g2;
Rectangle rec = new Rectangle(0,0,1280,1024);
Ellipse2D.Double ellipse = new Ellipse2D.Double(x1-240,y1-240,560,560;
Area area = new Area();
area.add(rec);
area.subtract(ellipse);
g2.setClip(area);

....something to do within the bounds of my new Shape...

It´s from the great Java_2D_Graphics -pdf
I read most of what I need right now...the rest will follow
Thanks again
Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

 « Reply #4 - Posted 2008-05-13 06:42:45 »

The problem with this approach is that it's not incredibly fast and you can't do something like make an Area masked by an image. There's little leeway.

If you want image manipulation, you should have a go at Raster and BufferedImage. Then you can just erase the pixels as you feel.

See my work:
OTC Software
Pyrodragoon

Junior Devvie

Art calculated with java...

 « Reply #5 - Posted 2008-05-13 16:43:15 »

Right, I got something wrong:

Graphics2D g2;
Rectangle rec = new Rectangle(0,0,1280,1024);
Ellipse2D.Double ellipse = new Ellipse2D.Double(x1-240,y1-240,560,560;
Area area = new Area(rec);
area.subtract(new Area(ellipse));
g2.setClip(area);
g2.drawImage(img,0,0,this);

This would draw an Image on the screen but only in the part thats not in ellipse.
It worked fine for now, my FPS didn´t decrease measureable.
Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

 « Reply #6 - Posted 2008-05-13 17:02:59 »

I stand corrected. It was on this very forum people told me you can't do that.

But in any case, Area operations are costly. If you did around 100 operations, you would most definitely notice slowdown on any computer. You can always just do this to be absolutely clear how much time you're using:
long temp = System.currentTimeMillis();
//insertt Area stuff here
System.out.println(System.currentTimeMillis() - temp);

It will help you diagnose the speed capabilities. Obviously just one operation won't hit performance too much, I'm just saying that it's pretty costly.

See my work:
OTC Software
Pyrodragoon

Junior Devvie

Art calculated with java...

 « Reply #7 - Posted 2008-05-13 21:21:49 »

Well with more Area actions it really is expensive concerning time...you were right
But what else should I do?
GeneralPath doesn´t help with this Problem either and I just want it done in Java2D...
Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

 « Reply #8 - Posted 2008-05-13 22:16:14 »

Well I'm not sure the exact nature of your project, so I can't give the best recommendation. How often are you doing this clipping? Would it be possible to do the clipping once and then save an instantiation of the Area object or the clipping Graphics context?

See my work:
OTC Software
Abuse

JGO Knight

Medals: 17

falling into the abyss of reality

 « Reply #9 - Posted 2008-05-13 23:42:24 »

One more thing to add - taken from the javadoc....

public abstract void setClip(Shape clip)

Sets the current clipping area to an arbitrary clip shape. Not all objects that implement the Shape interface can be used to set the clip. The only Shape objects that are guaranteed to be supported are Shape objects that are obtained via the getClip method and via Rectangle objects. This method sets the user clip, which is independent of the clipping associated with device bounds and window visibility.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
 Games published by our own members! Check 'em out!
princec

« JGO Spiffy Duke »

Medals: 495
Projects: 3
Exp: 16 years

Eh? Who? What? ... Me?

 « Reply #10 - Posted 2008-05-14 10:09:16 »

Maybe it's just me, but that really is a f**kwitted bit of software engineering isn't it? Building a function that is expressly going to fail when given certain arguments. I bet it doesn't even throw an exception.

Cas

Eli Delventhal

JGO Kernel

Medals: 42
Projects: 11
Exp: 10 years

Game Engineer

 « Reply #11 - Posted 2008-05-14 16:36:26 »

Hahaha.

I agree. I typically stay away from Java2D now, because a lot of stuff seems to be that way.

See my work:
OTC Software
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 BurntPizza (27 views) 2015-04-23 03:42:11 theagentd (31 views) 2015-04-22 16:23:07 Riven (44 views) 2015-04-16 10:48:47 Duke0200 (52 views) 2015-04-16 01:59:01 Fairy Tailz (38 views) 2015-04-14 20:13:12 Riven (41 views) 2015-04-12 21:36:37 bus hotdog (58 views) 2015-04-10 02:39:32 CopyableCougar4 (61 views) 2015-04-10 00:51:04 BurntPizza (62 views) 2015-04-06 22:06:58 ags1 (62 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 16x wessles 15x alwex 11x 65K 11x kingroka123 11x Rayvolution 9x kevglass 8x phu004 8x KevinWorkman 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x ra4king 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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