Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  Weird render glitch?  (Read 1843 times)
0 Members and 1 Guest are viewing this topic.
Offline roseslayer

Junior Member


Medals: 1



« Posted 2013-09-07 18:19:26 »

Hi there JGO,

I am experiencing a long time now a render glitch with is really been a pain in the "arssh". I never knew why this happened nor I wanted to ask it on the forums... But since I implemented mouseListener the coords are not always right because of lines that are bad drawn.

Normally a pixel in the game is 3 pixels from the screen but sometimes this 3 changes to 4 at several points (if you look at the grass/sand texture you will see bigger pixels that arent really 3x pixels but 4x (as in the ratio game:screen). I dont know what I am doing really wrong can't see something that is wrong.. Maybe it is just java and need to put more RAM into the game?

Screenshots:

information:
If you look at the inventoryGrid you see that some lines are 4 pixels wide and have the same draw code as others that are 3 pixels wide (what the normal ratio is). If you see at the left of the screen(top screenshot), then you see that the eyes of the MobPlayerMP are 4 wide aswell So I think I made a small error on how to draw the first coords or something.

Code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
public void render(int xPos, int yPos, int tile, int colour, int mirrorDir, int scale) {
      xPos -= xOffset;
      yPos -= yOffset;
     
      boolean mirrorX = (mirrorDir & BIT_MIRROR_X) > 0;
      boolean mirrorY = (mirrorDir & BIT_MIRROR_Y) > 0;
     
      int scaleMap = scale - 1;
      int xTile = tile % 32;
      int yTile = tile / 32;
      int tileOffset = (xTile << 3) + (yTile << 3) * sheet.width;

      for(int y = 0; y < 8; y++) {
         int ySheet = y;
         if(mirrorY)
            ySheet = 7 - y;
         int yPixel = y + yPos + (y * scaleMap) - ((scaleMap << 3) / 2);
         for(int x = 0; x < 8; x++) {
            int xSheet = x;
            if(mirrorX)
               xSheet = 7 - x;
            int xPixel = x + xPos + (x * scaleMap) - ((scaleMap << 3) /2);
            int col = (colour >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 8)) & 255;
            if(col < 255){
               for(int yScale = 0; yScale < scale; yScale++) {
                  if(yPixel + yScale < 0 || yPixel + yScale >= height)
                     continue;
                  for (int xScale = 0; xScale < scale; xScale++) {
                     if(xPixel + xScale < 0 || xPixel + xScale >= width)
                        continue;
                     pixels[(xPixel + xScale) + (yPixel + yScale) * width] = col;
                  }
               }
            }
         }
      }
   }


If you can help just say something It will always be great!
-RoseSlayer

Fundamentum W.I.P.
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #1 - Posted 2013-09-07 19:37:57 »

Your scaled image is not a multiple of three pixels wide or tall.
Offline roseslayer

Junior Member


Medals: 1



« Reply #2 - Posted 2013-09-07 20:06:31 »

Your scaled image is not a multiple of three pixels wide or tall.

How do you mean?

Fundamentum W.I.P.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roseslayer

Junior Member


Medals: 1



« Reply #3 - Posted 2013-11-05 20:43:27 »

Still the same problem and I can't seem to find the problem... It is getting really annoying when I am trying to add buttons some positions are wrong drawed :/.. Does anyone have an idea?

Fundamentum W.I.P.
Offline opiop65

JGO Kernel


Medals: 124
Projects: 7
Exp: 3 years


Team Alluminum


« Reply #4 - Posted 2013-11-05 22:19:46 »

Thats because your image has a border. When you render two images next to each other, it will look like your each slot has an extra pixel.

Offline Kyperbelt

Junior Member


Medals: 1



« Reply #5 - Posted 2013-11-06 01:55:52 »

try drawing your border with lines instead of using images with lines in them already
Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Reply #6 - Posted 2013-11-06 02:08:09 »

Without analyzing your code, I had a similar problem with a game for android that I made.
I was converting my position from double to integer to draw my images.
Example:
If you add 32.5 pixels each loop and you start at 0:
0 + 32.5 = 32
32.5 + 32.5 = 65

but 32 + 32 = 64... you have 1 extra pixel there.
Offline roseslayer

Junior Member


Medals: 1



« Reply #7 - Posted 2013-11-06 08:06:59 »

Thats because your image has a border. When you render two images next to each other, it will look like your each slot has an extra pixel.

try drawing your border with lines instead of using images with lines in them already

This graphical glitch only happends at certain coords on the screen. It are always the same coords. And because I think the images are moving constantly, that there is nothing wrong with the border. Still Thanks for trying to help!

Without analyzing your code, I had a similar problem with a game for android that I made.
I was converting my position from double to integer to draw my images.
Example:
If you add 32.5 pixels each loop and you start at 0:
0 + 32.5 = 32
32.5 + 32.5 = 65

but 32 + 32 = 64... you have 1 extra pixel there.

The problem is I am not using any doubles except from my movingspeed.. But still thanks for trying to help me!

Fundamentum W.I.P.
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #8 - Posted 2013-11-06 08:12:11 »

If you upgrade a 4-pixel wide image to 9-pixels wide, one of those pixels will be scaled to 3 times normal while the rest are only 2 times.

Of course this may not be your problem, but that's all I can guess from the information I have.

Offline roseslayer

Junior Member


Medals: 1



« Reply #9 - Posted 2013-11-06 08:35:10 »

If you upgrade a 4-pixel wide image to 9-pixels wide, one of those pixels will be scaled to 3 times normal while the rest are only 2 times.

Of course this may not be your problem, but that's all I can guess from the information I have.

This is exactly the problem the 4pixels wide pixel is sometimes scaled to 5pixels, But I can't seem to find where the code is wrong :/

Fundamentum W.I.P.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mads

JGO Ninja


Medals: 24
Projects: 3


One for all!


« Reply #10 - Posted 2013-11-06 08:59:03 »

How big is your original image, before any scaling? Never mind.

All I can think of is a rounding error somewhere with your ints.

EDIT: Actually, I don't even see it. And I couldn't check the actual width in Paint.NET, because the image is scaled. Sad

Offline roseslayer

Junior Member


Medals: 1



« Reply #11 - Posted 2013-11-06 09:50:12 »

How big is your original image, before any scaling? Never mind.

All I can think of is a rounding error somewhere with your ints.

EDIT: Actually, I don't even see it. And I couldn't check the actual width in Paint.NET, because the image is scaled. Sad

All the scales are most times 1, except text. I think it might be a graphical error that the 1 pixel is just missing and there is nothing rendered on it.. Or something.. But it keeps getting more and more annoying as I want to progress with my game :/

Fundamentum W.I.P.
Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Reply #12 - Posted 2013-11-06 14:24:41 »

I know a tutorial very similar with your game. Maybe if you check how it is made, you find what you have wrong.

DesignsbyZephyr tutorial
Offline roseslayer

Junior Member


Medals: 1



« Reply #13 - Posted 2013-11-06 14:42:49 »

I know a tutorial very similar with your game. Maybe if you check how it is made, you find what you have wrong.

DesignsbyZephyr tutorial

That is this game, only I took it a step further. He also has the render glitch but he probably doesn't saw it

Fundamentum W.I.P.
Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Reply #14 - Posted 2013-11-06 14:59:23 »

Where is you draw code?
Just to test it, make sure you scale all your tiles:

1  
g.draw(tile, x, y, SCALE_W, SCALE_H, null)
Offline roseslayer

Junior Member


Medals: 1



« Reply #15 - Posted 2013-11-06 15:49:15 »

Where is you draw code?
Just to test it, make sure you scale all your tiles:

1  
g.draw(tile, x, y, SCALE_W, SCALE_H, null)


all the colours from the render script are made into 1 single image, and then it is drawn:

1  
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);   

Fundamentum W.I.P.
Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Reply #16 - Posted 2013-11-06 15:50:44 »

Yes but you need to draw to that image before...
Offline lcass
« Reply #17 - Posted 2013-11-06 17:21:07 »

Hold up Ive seen that tutorial and had the same issue you use the image.getwidth and image.getheight when rendering. Look at the code below for the solution to that issue!!!. However if you have your sprites and an odd size and you are not compensating for it then you will have an issue like this.

vaanzeeban yes?

Edit :
if it is from the vanzeeban tutorials which it looks like it is goto this section of code
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
private void render() {
     
      BufferStrategy bs = getBufferStrategy();
      if (bs == null) {
         createBufferStrategy(2);
         return;
      }
      Graphics g = bs.getDrawGraphics();
      screen.clear();
     
      screen.render(xoffset, yoffset);
      for (int i = 0; i < pixels.length; i++) {
         pixels[i] = screen.pixels[i];
      }
      g.drawImage(image, 0, 0, image.getwidth(), image.getheight(), null);
      g.dispose();
      bs.show();

   }

and change it to
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
private void render() {
     
      BufferStrategy bs = getBufferStrategy();
      if (bs == null) {
         createBufferStrategy(2);
         return;
      }
      Graphics g = bs.getDrawGraphics();
      screen.clear();
     
      screen.render(xoffset, yoffset);
      for (int i = 0; i < pixels.length; i++) {
         pixels[i] = screen.pixels[i];
      }
      g.drawImage(image, 0, 0, WIDTH * SCALE, HEIGHT * SCALE, null);
      g.dispose();
      bs.show();

   }
Offline roseslayer

Junior Member


Medals: 1



« Reply #18 - Posted 2013-11-07 09:45:10 »

@Icass, thank you very much! And all the others that've been helping me to fix this problem. So it was a border problem

Fundamentum W.I.P.
Offline lcass
« Reply #19 - Posted 2013-11-07 16:29:39 »

Smiley not problem I had that issue for ages. Glad it worked!
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (35 views)
2014-04-15 18:08:23

BurntPizza (31 views)
2014-04-15 03:46:01

UprightPath (46 views)
2014-04-14 17:39:50

UprightPath (29 views)
2014-04-14 17:35:47

Porlus (46 views)
2014-04-14 15:48:38

tom_mai78101 (67 views)
2014-04-10 04:04:31

BurntPizza (127 views)
2014-04-08 23:06:04

tom_mai78101 (227 views)
2014-04-05 13:34:39

trollwarrior1 (192 views)
2014-04-04 12:06:45

CJLetsGame (199 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!