Skip to main content
gamedev.net
🔒 Locked

[java] regarding a 2D tile based engine..help!

Started by amemorex 5 replies 250+ views
Original Post
amemorex
amemorex
ok, here''s the deal. ive made quite a few 2D tile-based games in the past using straight API calls like BitBlt and what not..they all ran pretty fast, using simple win32 API commands is nice and easy to read, etc. well im currently working in java and basically im looking for a way to A. load images into an array, buffer, or something B. blit them out to the window in an easy manner, like blit(offsetX, offsetY, width, height, masktype). what should i look up? what library can achieve this in the most simplistic but efficient manner? ive heard of java2D but im not sure what the extent of it is, or if its overkill in this situation (ie: overloaded with useless stuff i dont need), or if its the ONLY thing i can use? basically what''s the most immediate way to jump from win32 API blitting in a C++ envrionment to drawing tiles in java. thanks!
stustill
stustill
Java2D is what you are looking for!

I am not an expert on the topic (check out www.javagaming.org it has lots of info) but I believe VolatileImages are what you are after. Trying asking about it there, someone with more knowledge should be able to help you

Stu
Akujin13
Akujin13
Easy topic.

What you want is some training in Pixel management. You can take any image and break it down into pixels using the PixelGrabber class. Then, you can reconstruct it using the MemoryImageSource class. Look both up and do some research. That should get you what you need to know.

-Akujin
-Akujin
Kentaro
Kentaro
Maybe this solution can also be practical, but I''m an idiot at graphics myself...

Create a BufferedImage that''s about screen width and screen height and pad it with about two tiles on all sides. Then use getGraphics() to get a Graphics object. Then, for an appropriate 2-dimensional array, use the drawImage method from the Graphics object. Once you''ve iterated over the entire array, you''ll have a nice back-buffer but you don''t want to write it to the screen yet because it has more than you need. Use the getSubImage() method to get a BufferedImage the size of the screen from the one you just created.

What does everyone think? I''m curious about rendering a 2D tile-based engine as well.

This isn''''t life in the fast lane, it''''s life in the oncoming traffic.
-- Terry Pratchett
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,fasting, good works and so on. Up until Doom, no one seemed to have thought about thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
nonnus29
nonnus29
I''m getting tired of pimping my stuff around here, I should just put it in a sig or something....

You can find the sources to two applet games on my site:

www.geocities.com/nonnus29/index.htm

and an example of a 2d side scrolling tile engine demo here (email me and I can get you a link to the source):

www.geocities.com/nonnus29/unionjack/test.htm


AWT is the way to go for making games; MemoryImageSource and BufferedImages are way overkill unless you want to do some interesting/wacko pixel effects. To me the only benefits of Java2d are effects like rotation and scaling which are too slow to be used in a game. And if anyone wants to play your game they will have to download a new JRE since 95% of users only have the OEM JRE. Of course the choice is yours.
Ditto Brother Rat
Ditto Brother Rat
Hey, if we all made high quality WebStart games then no one would mind downloading it. No one minds downloading the new DirectX every year, do they? OK, I do. Plus it does feel like a waste not to use jview.exe which is sitting on almost everybody''s drive (except the ones with WinXP I guess). But Swing, collections, JAXP, etc are so nice...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.