Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (603)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (650)
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  
  quadtrees and moving objects  (Read 1526 times)
0 Members and 1 Guest are viewing this topic.
Offline thalador

Junior Devvie

Projects: 1

« Posted 2007-05-10 14:27:09 »


I need a pointer on the whole quadtree thing.. Imagine there is a 2d space shooter game consisting of a lot of asteroids, ships, baseships and so on. The whole "world" is at least, say 100 x 100 Screens big, the user can fly around as he likes. My first thought was to divide the space with a quadtree to optimize the amount of draw calls. In every node would be a couple of game objects. Due to the nature of space shooter the objects move. If one object leaves a node I just have to delete it from the old and move it to a new one and so on. Thats not the problem. But what happens if I got a big baseship or something similiar that moves from one node to another ( see attachment)

There is a point in time, when I have to move the object from one node to another. At first glance I would say that is when the center of the object is now in the new node. But if I move the ship in that moment, it is clipped from screen but it should be seen a bit longer.

So my question is: How do you handle this, and is a quadtree the right tool for moving objects?
Offline Riven
« League of Dukes »

« JGO Overlord »

Medals: 1019
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #1 - Posted 2007-05-10 15:07:00 »

Put the item that overlaps nodes, in the 'parent' node (recursively, until it fits in 1 node) - then not only leafs have objects stored.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline appel

JGO Wizard

Medals: 69
Projects: 4

I always win!

« Reply #2 - Posted 2007-05-12 12:52:00 »

Sounds like a problem for scenegraphy engine.

Check out the 4K competition @
Check out GAMADU (my own site) @
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline fletchergames

Senior Devvie

« Reply #3 - Posted 2007-05-12 15:00:47 »

Just check every node that's adjacent to the screen for sprites in them that need to be drawn.

Even if you used the top-left corner (or whatever) instead of the center of the sprite for determining which node the sprite is in, you would still have the same problem in some cases.
Offline Riven
« League of Dukes »

« JGO Overlord »

Medals: 1019
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #4 - Posted 2007-05-12 15:03:48 »

If the item overlaps X nodes, you'd have to render a LOT of nodes outside the screen. To prevent that, use my previously posted solution.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline thalador

Junior Devvie

Projects: 1

« Reply #5 - Posted 2007-05-12 15:22:06 »

Thanks for your comments.
I will try to implement the method Riven suggested.

Recently I thought about another tree to implement a scenegraph: R Tree The wiki entry is not so good, so if you want to know more read this paper.
This tree is made to handle spatial data in multiple dimensions.. in this case it's only 2 dimensional and would hold rectangles. The nodes itself can overlap and their boundaries can grow, if you add new items to a node. The tree supports searching in areas for example questions like: which nodes are inside this arbitrary rectangle. If a nodes covered area gets to big, it's splitted up in smaller nodes similiar to quadtrees.
Advantages: moving objects just cause a node to grow, the don't leave the node -> this means you have to check the size from time to time, if it's to big -> split nodes
Disadvantages: I guess collision detection doesn't work so well, or is harder to implement

I didn't test this kind of tree yet, I just had spend a couple of moments to think about it.. what do you guys think?
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (16 views)
2015-07-29 04:35:27

Riven (37 views)
2015-07-27 16:38:00

Riven (19 views)
2015-07-27 15:35:20

Riven (22 views)
2015-07-27 12:26:13

Riven (12 views)
2015-07-27 12:23:39

BurntPizza (32 views)
2015-07-25 00:14:37

BurntPizza (42 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (31 views)
2015-07-22 22:16:53

NoxInc (20 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!