Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  Question about tile class  (Read 623 times)
0 Members and 1 Guest are viewing this topic.
Offline Bassex96

Senior Devvie


Medals: 4



« Posted 2013-05-23 01:48:10 »

Hey guys, i'm working on a pacman clone as we speak and i've got a couple simple questions. I've set the map up as a 2d array as board[][]. Right now, i'm just looping the array and drawing the block for the tile. I'm going to make a class for drawing the objects/sprites and I realized, I don't have any way to check collision of the tiles the way I have it as there is no rectangle..it just draws the tile. Should I make a new object for each tile so I can set a rectangle or bounding box for it?

Also, should this class be the same class I use to draw the pacman sprite? I don't think that would cause any issues, I just don't know if it would be a good idea to have a separate object for each and every tile. Is there an easier/better way?

Also, when I draw the tiles, they were rotated to the left it seems. I had to play with the values of the x and y and this is what I came up with which draws it correctly, but doesn't seem correct.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
   public void draw(SpriteBatch batch) {
      for (int y = 0; y < intHeight;y++) {
         for (int x = 0; x < intWidth;x++) {
         if (Board[x][y]==0) {
            batch.draw(blackTile, x*32, -y*32 + 576);
            System.out.println("Black");
         
         }
         
         if (Board[x][y]==1) {
            batch.draw(blueTile, x*32, -y*32 + 576);
            System.out.println("Blue");
         }
         
      }
      }
   }
}


I had to make the y value negative, i'm sure this is because of the reversed Y axis, but then had to add the screensize to the Y value...
Offline alaslipknot
« Reply #1 - Posted 2013-05-23 09:19:08 »

hello,
i faced a similar problem with the collision detection, and because i was working with lwjgl i couldn't use the intersect method that require 2 rectangle to check the collision, however, i build a similar method to do that, and it takes those integers variables as parameters
checkCollide(obj1_X, obj1_Y, obj1_Width, obj1_Height, obj2_X, obj2_Y, obj2_Width, obj2_Height)
and then i could do something similar to this :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
for (int y = 0; y < height; y++) {
         for (int x = 0; x < width; x++) {
                                // temporary X position of the block
                                int blockX = x * blockSize;
                                // temporary Y position of the block          
                                int blockY = y * blockSize;
                                //temporary type of the block
            String block = myWorld[y][x];
                                   
            // bx,by,bw,bh= the player x,y,width and height
            // if it's colliding with the tile blocks
            if (checkCollide(bx, by, bw, bh, blockX, blockY, blockSize,
                  blockSize)) {
               // if the tile block is from a specefic type
               if (block.equals("1")) {
                                            //do stuff
                                         }
                                   }
                   }

                 }
                     

so the whole point is to instead of using real rectangles, you just have to use their values (x,y,width and height)
i hope it helps,good luck

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #2 - Posted 2013-05-23 22:40:40 »

Thanks for the reply, but that has nothing to do with anything I asked lol. I don't have any problem with actually doing the collision detection. I just have no way to store the values for each tile unless I make a class and make a new object for every tile from the class. I was just wondering if there was a different way. I didn't know if it would be efficient to have 32*32 objects for just the tiles alone.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 138
Projects: 4
Exp: 3 years



« Reply #3 - Posted 2013-05-23 22:45:40 »

Since it appears you're using libgdx, I'd suggest you look at libgdx's (somewhat) new map api. Please note that any blog posts/wiki entries from 2011-2012 are probably outdated and using the old tiled-preprocessor package. Anyways - you can load tiled maps from the Tiled map editor, or .tmx format, or from the tIDE editor, and some other formats, and even if you don't want to bother with those you can still check out the source for libgdx's Cell class.
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #4 - Posted 2013-05-23 22:46:44 »

Since it appears you're using libgdx, I'd suggest you look at libgdx's (somewhat) new map api. Please note that any blog posts/wiki entries from 2011-2012 are probably outdated and using the old tiled-preprocessor package. Anyways - you can load tiled maps from the Tiled map editor, or .tmx format, or from the tIDE editor, and some other formats, and even if you don't want to bother with those you can still check out the source for libgdx's Cell class.

That's a pretty good idea. I want to actually use Tiled anyway, as I was going to change this to use it later.
Offline Bassex96

Senior Devvie


Medals: 4



« Reply #5 - Posted 2013-05-24 02:30:02 »

ARGH!!!

I just spent about 2 hours making the tileset and making the map, then added a new tile to the map for blockable tiles (I changed the size of the tileset but then changed it back) and now my map is all f**ked up! Is there anyway to fix this? If I can just change the tile indexes back to normal it should fix it but I can't find any way to do that....
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

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

toopeicgaming1999 (44 views)
2014-11-26 15:20:36

toopeicgaming1999 (8 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (26 views)
2014-11-25 11:26:43

Gibbo3771 (23 views)
2014-11-24 19:59:16

trollwarrior1 (36 views)
2014-11-22 12:13:56

xFryIx (75 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!