Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (223)
games submitted by our members
Games in WIP (813)
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  
  [SOLVED]Think im rendering wrong womehow (isometric)  (Read 1575 times)
0 Members and 1 Guest are viewing this topic.
Offline hapsburgabsinth

Junior Devvie





« Posted 2014-10-28 16:35:37 »

Hi, this is my first post. I really hope you can help me.

Im making a isometric game, with a cartesian map. the map is loaded from an image file into an array. The screen class stands for the renderen and gets the pixels from a pixel array saved in a Sprite, and put that pixel value into the Screens pixel array, and the screens draws its own array onto the screen.

Screens renderTile method gets the isometric coordinates, and draws them onto the screen.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
public void renderTile(int xp, int yp, Tile tile) {
      xp -= _xOffset;
      yp -= _yOffset;
      int color;
      for (int y = 0; y < tile.getSprite().getHeight(); y++) {
         int ya = y + yp;
         for (int x = 0; x < tile.getSprite().getWidth(); x++) {
            int xa = x + xp;
            if (xa < -tile.getSprite().getWidth() || xa >= _width || ya < 0
                  || ya >= _height) {
               break;
            }
            if (xa < 0) {
               xa = 0;
            }
            color = tile.getSprite().getPixels()[x + y
                                                 * tile.getSprite().getWidth()];

            if (color != 0xffff00ff) {
               _pixels[xa + ya * _width] = color;
            }
         }
      }
   }


Tiles render method takes the cartesian coordinates and convert them into isometric coordinates, and sends them into Screen, where they are draw as in the method above:
1  
2  
3  
4  
5  
public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y) / 2;
      int isoY = (x - y) / 2;
      screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
   }


I really appriciate your help Smiley
Offline philfrei
« Reply #1 - Posted 2014-10-29 03:48:18 »

Can you say a thing or two about how your code is failing? For example, is it not drawing at all, or drawing the wrong stuff, or drawing the wrong place, or giving error messages?

P.S. Welcome to JGO!

music and music apps: http://adonax.com
Offline Isvan
« Reply #2 - Posted 2014-10-29 04:28:06 »

Here is a link that really helped me with my now dead isometric game : http://gamedevelopment.tutsplus.com/tutorials/creating-isometric-worlds-a-primer-for-game-developers--gamedev-6511

If you really want here is the render code I had per tile (note 64 is the width of my tiles)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void render(float ZOOM,float DISPLACEMENT_X,float DISPLACEMENT_Y,SpriteBatch batch){
   
   
   renderX = x * (64 - ZOOM);
   renderY =  y * (64 - ZOOM);
   

   
   batch.draw(spr,/* X position */ (renderX - renderY) + DISPLACEMENT_X, /* Y position */ ((renderX + renderY) / 2) + DISPLACEMENT_Y ,width - (ZOOM * 2), ((width - (ZOOM * 2)) * ratio) );
   
}


If you are looking at the code, the only things that will matter are where I've put the comments

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline hapsburgabsinth

Junior Devvie





« Reply #3 - Posted 2014-10-29 04:29:17 »

Thank you! Smiley

Well it draws something. I have a picture of what it draws. The player is located at (0,0), but as you see, the drawing is wrong in some way Smiley

Offline hapsburgabsinth

Junior Devvie





« Reply #4 - Posted 2014-10-29 05:26:17 »

Here is a link that really helped me with my now dead isometric game : http://gamedevelopment.tutsplus.com/tutorials/creating-isometric-worlds-a-primer-for-game-developers--gamedev-6511

If you really want here is the render code I had per tile (note 64 is the width of my tiles)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void render(float ZOOM,float DISPLACEMENT_X,float DISPLACEMENT_Y,SpriteBatch batch){
   
   
   renderX = x * (64 - ZOOM);
   renderY =  y * (64 - ZOOM);
   

   
   batch.draw(spr,/* X position */ (renderX - renderY) + DISPLACEMENT_X, /* Y position */ ((renderX + renderY) / 2) + DISPLACEMENT_Y ,width - (ZOOM * 2), ((width - (ZOOM * 2)) * ratio) );
   
}


If you are looking at the code, the only things that will matter are where I've put the comments



That is the tutorial I've been using, but when I apply the math (as in the code for the render method in Tile. I now see that I divide by 2 in the isoX, that I have ficed now, but it still looks very weird:



the code for rendering tiles now looks like this:
1  
2  
3  
4  
5  
   public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y);
      int isoY = (x - y) / 2;
      screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
   }


Maybe I should mention that the map is loaded into an 2d array, so the map is in cartesian coordinates.
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 485
Exp: 7 years



« Reply #5 - Posted 2014-10-29 05:39:14 »

I don't have time atm to read through much, but take a scroll through this thread: http://www.java-gaming.org/topics/isometric-game-design/33434/view.html
Offline hapsburgabsinth

Junior Devvie





« Reply #6 - Posted 2014-10-29 05:56:27 »

I don't have time atm to read through much, but take a scroll through this thread: http://www.java-gaming.org/topics/isometric-game-design/33434/view.html

Found one mistake more. The Tiles render method now looks like:
1  
2  
3  
4  
5  
   public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y);
      int isoY = (x + y) / 2;     //Was - (minus) before
      screen.renderTile(isoX * WIDTH, isoY * HEIGHT, this);
   }


Now it looks like this:


It is like every second row hasn't the right offset?
Offline hapsburgabsinth

Junior Devvie





« Reply #7 - Posted 2014-10-29 06:21:16 »

I've changed the redering method in Tile to (got it from the link above (thanks):

1  
2  
3  
4  
5  
   public void isometricRender(int x, int y, Screen screen) {
      int isoX = (x - y);
      int isoY = (x + y);
      screen.renderTile(isoX * (WIDTH / 2), isoY * (HEIGHT / 2), this);
   }


I get the follwing when I use the code from above:

Offline Isvan
« Reply #8 - Posted 2014-10-29 06:38:43 »

Well that looks like its working? What is the array your providing look like?
Offline hapsburgabsinth

Junior Devvie





« Reply #9 - Posted 2014-10-29 07:21:43 »

Well that looks like its working? What is the array your providing look like?

Yes, now it actually looks right.

The map array is a 2d array in cartesian coordinates, and is stoed in the Level class.

Now I need to increase the area of tiles that is drawn, and fix the controls. Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 
cybrmynd (120 views)
2017-08-02 12:28:51

cybrmynd (144 views)
2017-08-02 12:19:43

cybrmynd (139 views)
2017-08-02 12:18:09

Sralse (154 views)
2017-07-25 17:13:48

Archive (624 views)
2017-04-27 17:45:51

buddyBro (733 views)
2017-04-05 03:38:00

CopyableCougar4 (1260 views)
2017-03-24 15:39:42

theagentd (1239 views)
2017-03-24 15:32:08

Rule (1216 views)
2017-03-19 12:43:22

Rule (1268 views)
2017-03-19 12:42:17
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

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!