Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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  
  Coordinates in a tiled world  (Read 1819 times)
0 Members and 1 Guest are viewing this topic.
Offline Phear

Senior Newbie





« Posted 2010-06-11 08:02:35 »

Hello,

I've tried out a couple of coordinate systems in a tiled world.
So far I'm not convinced that any of them is really what I'm looking for.

I'm working with a pacman clone (The level is tiled, but entities should be able to move freely).
The level is tiled from a 2d array. Each tile is 16x16.

My first attempt was just to use x:y coords for both objects and tiles.
(position and index in the tile-map). This resulted in pacman jumping from tile to tile
and not moving smoothly... clearly not what I was looking for.

My second attempt was to add delta coords for objects. This allowed me to
move the objects smoothly, but I feel using a delta is error prone. And should the major coord
be changed at the start/end/middle of a move?

Now I'm thinking about using different coordinates for objects and scenery.
And add a translation method. Does this sound like a good idea?

I would also like to have objects with larger than 1x1 tile sizes in the future.
Does any of the proposed coordinate systems limit this?

Thanks!
Offline zoto

Senior Devvie


Medals: 4



« Reply #1 - Posted 2010-06-11 08:47:45 »

You can use 2 different coordinate systems. The first you have already thought of based on the tiles index in the 2d array. The other system would be based on the pixel location. Have the character store its exact pixel location.

When you need to know what tile something is on just divide pixel location by the tiles size in pixels, 16 in your case.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2010-06-11 16:50:59 »

Typically for collisions I calculate the index location of the 4 corners of the object, but for movement I use pixel coordinates.

See my work:
OTC Software
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Phear

Senior Newbie





« Reply #3 - Posted 2010-06-14 07:54:16 »

Ok,
Makes sense.

Should the position of the objects be based on their center or top-left corner?
Will either affect the ability to have objects spanning several tiles?

Thanks!
Offline zoto

Senior Devvie


Medals: 4



« Reply #4 - Posted 2010-06-14 11:26:32 »

Base the position off the top left for a rectangular shaped object like your tiles. Use the center for circular shaped collision like on your creatures.

You can use java.awt.geom shapes to do a lot of the collision for you.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #5 - Posted 2010-06-14 17:26:04 »

Base the position off the top left for a rectangular shaped object like your tiles. Use the center for circular shaped collision like on your creatures.

You can use java.awt.geom shapes to do a lot of the collision for you.
Well as long as you're consistent using the center versus the top left corner (or any corner) makes no difference. So do whatever is easiest for you. Typically the only time you want the top left corner is for drawing images - otherwise the center is more convenient.

Although geom can indeed do collision algorithms, it  is by no means efficient about it. If you're interested in scaling your project to have a lot of collision going on or you're only going to be doing square and circle collisions, I wouldn't bother with geom.

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

 
EgonOlsen (1303 views)
2018-06-10 19:43:48

EgonOlsen (1161 views)
2018-06-10 19:43:44

EgonOlsen (900 views)
2018-06-10 19:43:20

DesertCoockie (1301 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1337 views)
2018-04-24 18:14:32

ivj94 (2079 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2213 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!