Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] Use mask or transparent gifs - a lot of questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 strf   Members   -  Reputation: 122

Like
Likes
Like

Posted 31 May 2000 - 07:32 PM

I have to make an isometric engine in JAVA. What is more efficient for drawing the tiles ? use transparent gif or use mask (via AlphaComposite i suppose) Some objects drawed may be animated ? how to draw only one object without redrawing all the scène ? is it possible to define a cliprect that is not rectangular ? What if i derive my objects from JComponent and put them in a JScrollPane? I want to cache graphics e.g i want to load graphics in memory only when needed and unload if not visible. How to force the GC to dispose unused graphics ? thanks

Sponsor:

#2 MadKeithV   Moderators   -  Reputation: 971

Like
Likes
Like

Posted 31 May 2000 - 09:14 PM

Transparent .gif is not a good way to go. There''s a patent problem with those images, and you aren''t allowed to freely post them. I know websites are COVERED in them, but the viable alternative is .png.

There was a HUGE outcry (on Slashdot for instance) about the .gif copyright enforcement a while back, that''s why I remember it.


#pragma DWIM // Do What I Mean!
~ Mad Keith ~

#3 Captain Goatse   Banned   -  Reputation: 100

Like
Likes
Like

Posted 01 June 2000 - 12:51 AM

I think best way to handle graphics are eiter use polygons or use BMP''s. BMP''s are usually faster than GIFs, but before it you must find a way to use BMP files in drawImage and get BMP file specs for Java. I used it while, but after I reformatted my hard drive I couldn''t find them anymore so I have to stick with gifs...

Time comes, time goes and I only am.

#4 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 June 2000 - 06:02 AM

I have never attempted to use the transparency capabilities of gif''s to make an iso-engine, so I can''t tell you what the pitfalls of that approach may be. Most examples of tile-based engines I have encountered (including the two that I have built) use transparency provided by the graphic API during blt operations or Alpha channel functions, so if you want to stick with the more widely used technique you would want to go that route.

The use of alpha channels also gives you additional capabilities that I would think you could not replicate using the transparency capabilities of the graphic files. For example, you may want to draw your tiles as rectangles and perform the isometric skewing at run time. This makes the creation of tile art much easier. Another possibility is to have semi-transparent areas on your tiles using the Alpha channels. You can achieve some interesting graphic affects like this (and it may help to deal with the border problem that occurs when you line tiles up in a grid).


#5 Captain Goatse   Banned   -  Reputation: 100

Like
Likes
Like

Posted 01 June 2000 - 08:05 AM

Oh and one thing, you better draw your iso tiles as unrotated but still in that shape what it''ll be when it''s rotated. I mean it''ll look kind of dummy if you rotate a normal square, because Iso tile isn''t a square it''s more like flattened down. Anyhow you should rotate them in your program because this way drawImage doesn''t have to draw the empty/transparent areas which would appear if you''d just draw that tile in program and now you have transparent areas for free!! Yahoooo! Bigger the image, less the speed and avoiding transparent sections is good way to avoid size.
One neat tip is to draw terrain tiles as 32x32 tiles and then other tiles as depth tiles like 32x32x64 for example. Then one way to do it is to plot pixels in polygon, it''s the fastest way but it''ll need work, work, work AND time, because you''ll have to draw shapes as pixel plots. I recommed this only if you can draw images as java''s pixel plots which would mean that you are A guru =)
Isotile

No compare this and rotated square? What do you think about it, It think this looks more iso tile that square which has been rotated 45 decrees.


Time comes, time goes and I only am.

#6 Erik_N   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 June 2000 - 02:40 PM

Transparent gif works very good with Java. It will be faster then using a mask. It even displays them animated if they are, but with double-buffering I have a ugly flicker problem with animated gif''s. If you time the gif settings right with the framerate you might get around this.Standard double buffering like the one''s JComponent & JPanel provide do not bothor it only manual double buffering.
>What if i derive my objects from JComponent and put them >in a JScrollPane?
Sounds fine.If you are extending this for drawing areas you can redraw each JComponent as needed so only redraws the component you want not the whole scene.

>I want to cache graphics e.g i want to load graphics in >memory only when needed and unload if not visible. How to >force the GC to dispose unused graphics ?

Set your images to null and tell the gc to run on all null objects. Like this
image1 = null;
System.runFinalization();








#7 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 01 June 2000 - 03:17 PM

>I mean it'll look kind of dummy if you rotate a normal square

Actually, you do use just normal squares. When you create the surface that you will use to blt to the screen you have to perform two operations. The first operation rotates the square tile, the second 'resizes' it to decrease the y dimensions of the rotated tile by 50%. You end up with the same isometric tile shape. Since you do this just once for each tile image (for instance, at the begining of the level of begining of the game) it is not computationally expensive.

As an aside, if you are using a 3D engine to simulate a 2D isometric view its even easier. The square tile image will be skewed to the proper angle when it is applied as a texture to the 3D 'tile'.

Edited by - Jerry Lynn on June 1, 2000 10:19:58 PM

#8 SteveMeister   Members   -  Reputation: 122

Like
Likes
Like

Posted 02 June 2000 - 12:40 AM

AffineTransform is your friend! :-)

When using Java2D, the Graphics2D instance has a current transform. You can get this transform and adjust it just as you would in a 3D environment. For example, you can do translate, rotate, scale, and shear the Graphics2D any time you want. So if you have a square tile that has its own local coordinate system and you want to display it isometrically, you can apply shear and translate transforms just before drawing it normally.

Java2D is really good at stuff like this, and it''s also optimized for the hardware it''s running on. Learn it and use it well! :-)

#9 strf   Members   -  Reputation: 122

Like
Likes
Like

Posted 03 June 2000 - 12:02 AM

Thanks for your help

I think that i will use JComponent with transparent GIF(or PNG, i must try) for my objects, and put them in a JScrollPane.
Use Graphics2D transforms seems interesting but the tiles borders should not be very clean. How to make seamless tiles ?

I have an another question :
Some objects may have multiples images, like animated gifs.
I don''t know what is more interesting :
- each object have a thread, that will rotate the images
- one unique thread for all of the objects


#10 Captain Goatse   Banned   -  Reputation: 100

Like
Likes
Like

Posted 03 June 2000 - 01:19 AM

Seamless tiles, well that is hard question. I do them like this: Firstly I have html file which background is that tile, then I just make the basic shape and refresh it. This doesn''t work with Iso tiles, but it''s usually testing, test&blur right places or cut and paste.

Using animated gifs is not recommed, because some systems mess them up and when you move them, they are messed too, well at least on my system.

For that latter question I would answer that you should create one thread for whole painted area at the same time. Those multiple threads will be reaallly slow. The point in that one thread thing is that you add each visible object to that thread and then paint the right objects while everything else is untouched, but when it moves it updates everything, this way those tiles won''t be "late" after scrolling.

Time comes, time goes and I only am.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS