Show Posts
|
|
Pages: [1]
|
|
2
|
Game Development / Newbie & Debugging Questions / Re: Drawing images
|
on: 2011-04-05 18: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...  Thank you!
|
|
|
|
|
3
|
Game Development / Newbie & Debugging Questions / Re: Drawing images
|
on: 2011-04-05 17: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 16: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 16: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  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 15: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 18: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.
|
|
|
|
|
11
|
Game Development / Newbie & Debugging Questions / Object Movement
|
on: 2011-03-07 13: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:
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|