Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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!

               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]
nelsongames (19 views)
2018-04-24 18:15:36

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

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

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

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

Solater (65 views)
2018-03-17 05:04:08

nelsongames (110 views)
2018-03-05 17:56:34

Gornova (175 views)
2018-03-02 22:15:33

buddyBro (746 views)
2018-02-28 16:59:18

buddyBro (93 views)
2018-02-28 16:45:17
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!