Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 1306 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
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 130
Projects: 4
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: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« 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: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!