Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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] Updating Block Textures (Joined Boxes?) [3D]  (Read 788 times)
0 Members and 1 Guest are viewing this topic.
Offline GabrielBailey74
« Posted 2013-06-24 05:47:26 »

Hello JGO, today I've been messing around with cubes in a 3D application ^_^
Basically what I'm trying to accomplish is shown in the images below, but I'll also explain it:
Quote
Say there is 4 blocks stacked on top of each other.
I'd like the bottom 3 to be textured solid while the top block is textured as a top block. (Signifying a difference)

Here is what I am starting with:


I'm trying to accomplish something around the lines of:


Now I have been experimenting with this for the past few hours and I can't seem to write a method that "Dynamically" adjusts.

Here is the method at the moment (Clean restart, was WAY too long):
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  
   /**
    * Updating the blocks texture.
    * @param parentChunk The chunk to iterate through.
    */

   public void updateBlockTexture(Chunk parentChunk) {

      // obtain a instance of this block (class)
      final Block b1 = (Block) this;

      // iterate through the parent chunk's blocks.
      for (int i = 0; i < parentChunk.getBlockList().size(); i++) {

         // obtaining a block from the list.
         final Block b2 = parentChunk.getBlockList().get(i);

         // are the blocks identical?
         final boolean identical = Boolean.valueOf(b1 == b2 || b2 == b1);

         if (!identical) {

            // check if b1 is ontop of b2
            if (b1.isOntopOf(b2)) {

               // updateB2.texture -> solid block texture (Vice Verca)
            }
           
            // check if b2 is ontop of b1
            if (b2.isOntopOf(b1)) {
               
               // updateB1.texture -> solid block texture (Vice Verca)
            }

            // TODO: Check blocks on top of blocks.
         }
      }
   }


When I wrote a somewhat decent version of this earlier I managed to get it to do what I want, but when I changed the chunks size It wouldn't function properly xD.

If somebody whose done this before could help me out with a explanation / pseudo code or if anybody could link me to a tutorial I'd be very grateful thanks JGO ^_^

If you need anymore information, please ask ^_^

Offline HeroesGraveDev

JGO Kernel


Medals: 310
Projects: 11
Exp: 3 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-06-24 06:09:01 »

Just use different blocks for the top and fill.

Offline GabrielBailey74
« Reply #2 - Posted 2013-06-24 06:16:05 »

Just use different blocks for the top and fill.

Almost sounds like you're stating the obvious lol Roll Eyes Roll Eyes Roll Eyes.

Or maybe I didn't explain what I'm trying to accomplish well enough ^_^

Of course I want to use a different block texture for the top one xD each block is independent in the world so it has to be dealt with (In the method) independently.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline GabrielBailey74
« Reply #3 - Posted 2013-06-24 06:48:36 »

Great, I solved it ^_^

Thread closed.

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  
   /**
    * Updating the blocks texture.
    * @param parentChunk The chunk to iterate through.
    */

   public void updateBlockTexture(Chunk parentChunk) {

      // iterate through the parent chunk's blocks.
      for (int i = 0; i < parentChunk.getBlockList().size(); i++) {
         // obtain a instance of this block (class)
         final Block b1 = (Block) this;
         // obtaining a block from the list.
         final Block b2 = parentChunk.getBlockList().get(i);

         // are the blocks identical?
         final boolean identical = Boolean.valueOf(b1 == b2 || b2 == b1);

         if (!identical) {

            // check if b1 is ontop of b2
            if (b1.isOntopOf(b2)) {
               b2.setSideTextures("Bottom");
               Game.debug(b1.toString() + " is on top of " + b2.toString());
               break;
               // updateB2.texture -> solid block texture (Vice Versa)
            }

            // check if b2 is ontop of b1
            if (b2.isOntopOf(b1)) {
               Game.debug(b2.toString() + " is on top of " + b1.toString());
               break;
               // updateB1.texture -> solid block texture (Vice Versa)
            }

            // TODO: Check blocks ontop of blocks.
         }
      }
   }

Offline sproingie

JGO Kernel


Medals: 202



« Reply #4 - Posted 2013-06-26 22:36:30 »

Minecraft used the "grass topped block", but there's really no reason to slavishly copy this design.  How about implementing the ability to compose blocks out of a base block and decorations?  Then you just draw all dirt blocks and "paint" decorations on top.  Sure it's more complex but I think you can see some advantages to this too.

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.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (21 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (49 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!