Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (541)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 / Java Decompilation on: 2011-04-06 18:12:59
Is there a way to protect Java class files from decompilation or at least make decompilation more difficult?
2  Game Development / Newbie & Debugging Questions / Re: Drawing images on: 2011-04-05 16:35:38
1  
2  
3  
4  
g2d.setPaint(Color.red);
Rectangle2D f = new Rectangle2D.Double(100 + x, 250 + y, 32, 32);
g2d.fill(f);
g2d.drawImage(boxTexture, (int)Math.round(100 + x), (int)Math.round(250 + y), null);


planC

instead of g2d.fill(f)
could you try
g2d.fillrect(f.x, f.y, f.width, f.height);

It may require you to cast (int)  and use the same method as you do for your drawImage

either just leave "both (int)  with no round", or both "drawimage and fillrect with (int)math.round"


plan D

1  
2  
3  
4  
5  
g2d.setPaint(Color.red);
Rectangle2D f = new Rectangle2D.Double(100 + x, 250 + y, 32, 32);

g2d.fillrect((int)f.x, (int)f.y, f.width, f.height);
g2d.drawImage(boxTexture, (int)f.x, (int)f.y, null);


This should allow both the filled rect and image to be the same pixel locations
While maintaining the rectangles double precision(for collision detection or other "high resolution/ sub pixel accuracy"



edit:
Could I inquire to why you need both an image and a filled red rectangle occupying the same location?  Will the image or red rect not just obstruct the other from sight?
Because although I'd like to continue to help you solve your problem the method you'd like to. Perhaps there is another underlying better solution to the whole thing?



This is working just fine. The rectangle and image now are drawn at the same x and y pixel location. I use I high precision collision detection so the drawback of this approach is that a collision is detected before the two rectangles touch (there is one pixel gap between them or one box is 1 pixel on top of the other because double precision coordinates for collision detection are used). But this is not very noticeble and it solves my problem. The image doesn't move from left to right anymore (when the rectangle was moving fast it seemed like the image was shaking).

Yes, the image will obstruct the rectangle and the reason it was painted in red is just for debugging... Smiley
Thank you!
3  Game Development / Newbie & Debugging Questions / Re: Drawing images on: 2011-04-05 15:02:56
Ok, plan B. try;
1  
2  
3  
4  
5  
6  
7  
g2d.setPaint(Color.red);
Rectangle2D f = new Rectangle2D.Double(100 + x, 250 + y, 32, 32);
g2d.fill(f);

AffineTransform at=new AffineTransform();
at.translate(100+x,250+y);
g2d.drawImage(boxTexture,at,null);


Nope, the result is the same. I am hoping someone's gonna give me plan c
4  Game Development / Newbie & Debugging Questions / Re: Drawing images on: 2011-04-05 14:49:02
You're using Math.round() to draw your image;
1  
g2d.drawImage(boxTexture, (int)Math.round(100 + x), (int)Math.round(250 + y), null);
try it without;
1  
g2d.drawImage(boxTexture, (int)(100 + x), (int)(250 + y), null);


Yes I tried that, didn't solve the problem. But then have a look at the second code which uses TexturePaint. It doesn't use Math.round() so I think it must be something else...
5  Game Development / Newbie & Debugging Questions / Re: Drawing images on: 2011-04-05 14:37:12
I tried it without using Math.round() and it didn't help. This code doesn't even use Math.round() but it still causes the same problem. Image and rectangle coordinates don't match Sad

1  
2  
3  
g2d.setPaint(new TexturePaint(boxTexture, new Rectangle.Double(100 + x, 250 + y, boxTexture.getWidth(), boxTexture.getHeight())));
Rectangle2D f = new Rectangle2D.Double(100 + x, 250 + y, 32, 32);
g2d.fill(f);
6  Game Development / Newbie & Debugging Questions / Re: Drawing images on: 2011-04-05 13:36:19
Hello again. I use this code to draw a rectangle and then a 32x32 image on top of it. The problem is that when x and y change the coordinates of the rectangle and image are not always rounded to the same number, sometimes the image is 1 pixel further than the rectangle. When I round the x and y before this code they are drawn in the same position, but I can't do that, I have to create the rectangle giving it the x and y in double precision.

1  
2  
3  
4  
g2d.setPaint(Color.red);
Rectangle2D f = new Rectangle2D.Double(100 + x, 250 + y, 32, 32);
g2d.fill(f);
g2d.drawImage(boxTexture, (int)Math.round(100 + x), (int)Math.round(250 + y), null);



I also tried this code but again I got the same result:

1  
2  
3  
g2d.setPaint(new TexturePaint(boxTexture, new Rectangle.Double(100 + x, 250 + y, boxTexture.getWidth(), boxTexture.getHeight())));
Rectangle2D f = new Rectangle2D.Double(100 + x, 250 + y, 32, 32);
g2d.fill(f);


Any ideas how to fix that?  :/
7  Game Development / Newbie & Debugging Questions / Re: Drawing images on: 2011-04-01 16:34:47
I have a rectangle2d moving on the screen with double precision using vectors and I want to draw an image on top of the rectangle. When the rectangle is moving the image just does not stay on top of it all the time because its drawn with double precision and the image with integer.
8  Game Development / Newbie & Debugging Questions / Drawing images on: 2011-04-01 15:58:41
Is it possible to draw an image with double precision? Im using a drawImage method, but it only takes integer coordinates.
9  Game Development / Newbie & Debugging Questions / Re: Object Movement on: 2011-03-07 15:48:43
Thank you. I will do some reading on vectors.
10  Game Development / Newbie & Debugging Questions / Re: Object Movement on: 2011-03-07 13:26:14
But how do I find the x,y coordinates of the red wall to move it to that direction? How much the the x,y needs to be increased/decreased while the button is pressed?
11  Game Development / Newbie & Debugging Questions / Object Movement on: 2011-03-07 12:03:06
Hi all! I have a circle which always stays in the center and rotates so that it always faces the mouse cursor (the red line on the circle indicates the direction of the cursor). What I want to do is when I hold the Up arrow key I want the red walls to start moving towards the circle at the angle indicated by the red line on the circle and when I hold Down arrow key I want the walls to move to the opposite direction. Can you please give me some ideas on how this can be achieved. Here is a screenshot of my application:

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.

Mr.CodeIt (24 views)
2014-12-23 03:34:11

rwatson462 (55 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (86 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (81 views)
2014-12-05 12:39:02

SHC (91 views)
2014-12-03 16:27:13

CopyableCougar4 (98 views)
2014-11-29 21:32:03

toopeicgaming1999 (157 views)
2014-11-26 15:22:04

toopeicgaming1999 (154 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!