Results 1 to 15 of 15
  1. #1
    Theloneslaya is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Question How to create a block id(for a game)

    Hi everyone, i know these fourms aren't too big on games but i need help on creating block ids.
    2-d game, i have 3 objects/sprites up and running, i just need to know how to set them to specific block ids. They all have an individual class file. Thanks if anything!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,409
    Rep Power
    20

    Default Re: How to create a block id(for a game)

    Since I haven't a clue what a 'block id' might be, I'm assuming it's something game programmers might know about. Which is why I've moved this thread here from New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Theloneslaya is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    oh thanks, i kinda get lost here

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,084
    Rep Power
    6

    Default Re: How to create a block id(for a game)

    Yeah I'm an amateur game programmer and I can say that there it is not something game development specific, making this question very vague. To me a "block ID" is a simple integer which you get with a self-incrementing method.

    Java Code:
    int id = 1;
    
    public final int getNextID(){
      return id++;
    }

  5. #5
    Theloneslaya is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    Thanks alot! This really helped.

  6. #6
    Theloneslaya is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    Now how to use it. Saying something like grass(2-d) has block id of 1. (assuming all display and creation methods are done) how would i implement that to use instead of GrassTile.? Something like getID(1)?

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,084
    Rep Power
    6

    Default Re: How to create a block id(for a game)

    I don't believe you really thought this through. In stead of diving into code why don't you try explaining, to yourself first to make sure at least you understand it, in normal English what you are trying to achieve.
    Last edited by gimbal2; 07-10-2013 at 12:32 PM. Reason: stupid typo

  8. #8
    Theloneslaya is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    i already know exactly what im doing, i just need this to work for it all to take place

  9. #9
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,084
    Rep Power
    6

    Default Re: How to create a block id(for a game)

    Well then you don't need help, just patience.

  10. #10
    Theloneslaya is offline Member
    Join Date
    Apr 2013
    Posts
    12
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    You should probably re-read all of that to process it a little better.

  11. #11
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to create a block id(for a game)

    Quote Originally Posted by Theloneslaya View Post
    Saying something like grass(2-d) has block id of 1.
    This makes very little sense. "Block ID" is doesn't have any specific meaning. My best guess is that you're talking about sprites or tiles, but it's still not clear what you're asking.
    Get in the habit of using standard Java naming conventions!

  12. #12
    paul59539 is offline Member
    Join Date
    Nov 2013
    Posts
    3
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    Maybe you're searching for somethings else and not about block IDs....

  13. #13
    Join Date
    Nov 2012
    Posts
    29
    Rep Power
    0

    Default Re: How to create a block id(for a game)

    Hello there!
    Just got back on these forums, and having been on java-gaming.org, that took a bit...
    I would suggest that you go to that forum, since it is a bit more centered on game topics, and has a very good community.

    Now, I usually go about blocks (tiles) in general:
    Java Code:
    public class Tile {
    	// All of the Tiles will be adding their id to this on creation.
    	public static final HashMap<Integer, Tile> TILE_IDS = new HashMap<Integer, Tile>();
    
    	public static Tile dirt0, dirt1, dirt2, stone0, stone1, stone2, wood0, wood1, woodplank, woodplankfloor;
    
    	public static void initTileResources(/*    This is where you will initialize all of the resources for the tiles.    */) {
    		
    	}
    
    	public static Tile getTile(int id) {
    		return TILE_IDS.get(id - 1);
    	}
    }
    When I need to use a tile, I will call getTile() to get the singleton tile, and render it at a specified position.

    One thing you NEED to make sure you do, is to not treat tiles like entities (i.e. having a Tile[][]). It is inefficient to render all of those tiles with seperate textures, rather than rendering the singleton tile at a given point. It will save you a lot of frustration in the longrun.

    Hope this helps!

    -wes

  14. #14
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,084
    Rep Power
    6

    Default Re: How to create a block id(for a game)

    Its good advice to point people to java-gaming.org for Java game programming topics (although you kind of unintentionally imply that it has a good community and this one does not...), but you are making lots of assumptions in your answer. You shouldn't do that because then YOU lead the OP; it should be the other way around. First the OP needs to know what he/she wants and be able to explain that, then its time to discuss implementation details.

    In any case, the thread is already kind of stale.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    pj6444 is offline Senior Member
    Join Date
    Jan 2013
    Posts
    165
    Rep Power
    2

    Default Re: How to create a block id(for a game)

    You can just have a Block or Tile class in you project. Just make the class like this..

    Java Code:
    public class Block extends Rectangle {
        
        private int id;
    
        public Block(int x, int y, int id) {
            setBounds(x, y, 32, 32);
            this.id = id;
        }
    
    }
    This will give individualized id's for each object that you create.

Similar Threads

  1. want to add BLOCK into snake game
    By nabil in forum New To Java
    Replies: 4
    Last Post: 03-30-2012, 04:39 PM
  2. What to use to create a game?
    By Tombomb in forum New To Java
    Replies: 7
    Last Post: 01-13-2012, 08:41 PM
  3. How to create a block method?
    By Anza Power in forum Threads and Synchronization
    Replies: 4
    Last Post: 12-26-2011, 05:18 PM
  4. Modify/create AVI's INFO BLOCK
    By Agus211 in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 03:20 PM
  5. Create the game Hangman
    By barney in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •