Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (602)
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  
  Creating a Specific Collision Area on a Larger Sprite  (Read 1995 times)
0 Members and 1 Guest are viewing this topic.
Offline SJS

Junior Newbie

« Posted 2013-04-29 17:17:49 »

Hi Everyone,

First time poster on these forums so I hope somebody is able to help or point me in the right direction.

I'm currently writing only my second ever java game from scratch, not using a framework of any kind yet (maybe that would help with this issue), but have run into a problem that has me a little stumped. Huh

The game i'm working on is a missile command style game, however with real missile sprites raining down on city sprites.  Now I have my AffineTransform rotating my missiles to the correct angles (which are randomly generated) based on a start and end X and Y (again both randomly generated) BUT my bounding box for each missile is obviously not rotating with the missile.  The even bigger problem is that even if I get the bounding box to rotate to envelope the image the image itself has too much blank space either side which would count as a collision when none actually occurred. 

Is there some way for me to implement a smaller bounding collision box for my larger image which also follows the rotation of that image??  If only the tip of the missile counted as a collision instead of the whole missile that would be a bonus!

Thanks!  Grin
Online Jimmt
« League of Dukes »

JGO Kernel

Medals: 162
Projects: 5
Exp: 3 years

« Reply #1 - Posted 2013-04-29 17:32:13 »

Why is rotating the bounding box a problem? If the original bounding box was ok why would it be too big when rotated?
Offline SJS

Junior Newbie

« Reply #2 - Posted 2013-04-29 17:47:39 »

At the moment my missile image is 40 x 40 but the actual missile is only around 40 by say 12 with the rest being transparent.  The reason I changed it to 40 x 40 was so that when I used AffineTransform the rotation worked, whereas when the image was 40 x 12 the rotation would not work correctly.

If this is the problem then I can post my code and maybe somebody can point me to the correct way to rotate a 40 x 12 image the right way along with the bounding box?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-04-29 18:08:55 »

You can also make your collision area using a Polygon. Or, building it from multiple Circles/Rectangles. The benefit of the latter solution is that you can use sequentially smaller "level of detail" for more efficient collision checking. Here's an image to demonstrate:

The image is taken from this great e-book, which is a great resource if you plan on writing your own 2D collision detection:
2D Game Collision Detection - Thomas Schwarzl

Offline SJS

Junior Newbie

« Reply #4 - Posted 2013-04-29 19:12:51 »

Yes this is exactly what I need  Cheesy

Although I will definitely buy this book, probably next week, is there any other resources that I can look at online that will explain how to achieve this same thing so I don't have to wait? 
Offline wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

« Reply #5 - Posted 2013-04-29 22:11:02 »

Its a kindle book so you don't have to wait anyway Smiley

Offline SJS

Junior Newbie

« Reply #6 - Posted 2013-04-30 00:41:35 »

Its a kindle book so you don't have to wait anyway Smiley

Are you offering to pay??  Tongue
Offline wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

« Reply #7 - Posted 2013-04-30 00:59:01 »

No need to buy a kindle just use the app!

Offline SJS

Junior Newbie

« Reply #8 - Posted 2013-04-30 02:20:11 »

 Grin I meant the money for the ebook.. Anyway thanks for the link, as I said I will buy it sometime this week when I have some money in my paypal account (it's easier for me to do it that way). 

I'd still appreciate any other links to similar solutions?!  Wink
Offline relminator
« Reply #9 - Posted 2013-04-30 05:05:00 »

Depending on your needs, the solution posted by davedes is fast and good enough(I used something like that on my nintendo ds game called "bubble fight ds").

You could also use aabb or sat or a combination of them all.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Roquen
« Reply #10 - Posted 2013-04-30 09:48:46 »

A hierarchy of bounding circles is a fundamentally flawed solution assuming you want accurate and fast "intersections".  And why on earth do people always forget about GJK.
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 (18 views)
2015-07-27 15:35:20

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

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

BurntPizza (30 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!