Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
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   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Rotating a Rectangle object on: 2011-01-27 17:32:57
Thanks a lot!
I removed the Rectangle inheritance, and simply put a Shape, plus x,y, width and height values in my GameObject class (which Tank now inherits)
And this solved my problem so far. Now my tank will bump into Tiles (which also inherit GameObject).
However, these Tiles always have a Rectangle as Shape, so I can simply do Tank.Shape.intersects(Tile.Shape).

But then how would I go about checking collisions with other GameObjects which have had their Shape rotated?
Is there a way to do this using features in Java2D, or will I have to write something myself?
2  Game Development / Newbie & Debugging Questions / Rotating a Rectangle object on: 2011-01-26 21:28:23
Hi guys,

I wanted to make a simple 2D tank game, just for fun.
I'm having 1 major problem however, and I feel it should be easy to solve, but I just can't find the answer anywhere.

I have a Tank class, which extends Rectangle (java.awt.Rectangle)
It contains an image, which I am easily able to rotate using Graphics2D's rotate method.

I want to use the Rectangle.intersects method, but while the image moves exactly like I want it to, the object itself will not change (it changes location, but not it's shape), meaning the image can easily go through walls before stopping.

The problem however, is that I can't get a Tank -object-to rotate.
Using AffineTransform, I can get a rotated version of the tank Rectangle to appear just as I want it...but I can't get the newshape into my Tank object!

I tried using getBounds, but that doesn't return the actual shape, just a rectangle that encloses the shape.
I believe I need to use Tank.setFrame...but I can't get newshape's frame, or x/y location or dimensions for that matter.
What am I doing wrong here? Please help!

Quote
               Tank t = (Tank) o;                

                AffineTransform at = AffineTransform.getRotateInstance(t.getFacing(), t.getCenterX(), t.getCenterY());
                Shape newshape = at.createTransformedShape(t); //creates a new, rotated version of Tank t
                
                g2d.draw(newshape); //draws the new, rotated version of the Tank. This looks perfect, just like I want it

                /*
                THE PROBLEM: I need to apply newshape to my tank, but HOW?
                */

                g2d.drawRect(t.x, t.y, t.width, t.height); //this draws a rectangle where the Tank object is situated, this one is static, except for it's location, no rotation or such.
                
                g2d.rotate(t.getFacing(), t.getCenterX(), t.getCenterY()); //this rotates and draws the Tank's image, works as it should.
                g2d.drawImage(t.getMainImage(), t.x, t.y, null);

Pages: [1]
 

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 (28 views)
2014-09-12 09:08:26

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

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

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

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

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

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

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

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

mitcheeb (40 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!