Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Bravolino

[java] Jumping into 2D arrays

This topic is 6038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so i know i''ve been bugging people for awhile about this, but basically, i want to start coding with graphics, something where I can access premade tiles and put them on the screen using a 2D array. So far i''ve been told that if i want to store an image i have to code: import java.awt.Image //later Image [][] board = new Image [50][50] //creates 50x50 board What do i do after that to store my images, either jpgs or bitmaps or gifs, into the array? How can I make tiles which have a transparent aspect to them?, like a player tile tha moves on top of the other tiles, so that i can see the tile beneath the player? Where''s the best place to learn 2D graphics, that is informative and well written? Thanx Mike

Share this post


Link to post
Share on other sites
Advertisement
Well having a [50][50] array of images is not the right way to go, unless you want to use heaps of memory.
Istead you''d store an array of the dimensions of each tile, then get a subImage of the main image when you need it.

Getting the player to be on top just means you need to draw the player last.

check out quad trees to make each tile.
http://www.gamedev.net/reference/programming/features/quadtrees/

Share this post


Link to post
Share on other sites
When I make tile-based games, I typically start by making a tile class that will hold information about the tile such as the current image to display in it, any contents in the tile such as people, trees, scorch marks, etc..., coordinates of the tile, etc...

I create a 50x50 array of the tile objects (I chose 50x50 because that is what you were doing in your post), and then all I need to do to draw each tile is call a method such as tileObj.drawTile() for all tiles that need updating.

To create the illusion of having objects transparently on top of a background, draw the background first, then draw the next layer, then the next layer, and so on until you get to the uppermost item.

If you are going to allow objects to smoothly move between tiles, you may need to store the object coordinates separately from the tiles themselves, although you can certainly test to see if the object lies within the tile it is moving over.

Anyway, I hope that helps!

Share this post


Link to post
Share on other sites
Also, the easiest way to use transparency is to have a transparent gif. Java takes care of the details for you if you do it this way.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!