Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (515)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
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 2423 times)
0 Members and 1 Guest are viewing this topic.
Offline Pyrodragoon

Junior Duke




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?
Offline Eatserbeam

Junior Newbie





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

  I hope this help you
 
                         [url removed]

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

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

Junior Duke




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!
Legends of Yore - The Casual Retro Roguelike
Offline Pyrodragoon

Junior Duke




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  Wink
Thanks again  Smiley
Offline 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
Offline Pyrodragoon

Junior Duke




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.
Offline 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.  Tongue

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
Offline Pyrodragoon

Junior Duke




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  Embarrassed
But what else should I do?
GeneralPath doesn´t help with this Problem either and I just want it done in Java2D...
Offline 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
Offline Abuse

JGO Knight


Medals: 13


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!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 409
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 Smiley

Offline 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (30 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (39 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (25 views)
2014-10-26 10:14:04

theagentd (31 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!