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  
  [Solved]Slick2d - Rendering only a part of the map - need all of it  (Read 1466 times)
0 Members and 1 Guest are viewing this topic.
Offline Azulon

Senior Newbie


Medals: 1



« Posted 2011-11-27 17:48:08 »

I posted the same thing on Slick forums - posting here as well because slick forums aren't very active.

So I created a map using Tiled. I loaded into my game world.

I went through each tile and layer and added the objects I needed such as the entities and the collision objects.

It renders them all correctly and all works dandy except when I move my camera around it doesn't do it anywhere else other than the width of the frame. It is missing 3/4s of the map.

I use map.render(0,0) and it renders the rest of the map, but the entities aren't there, no hit box, etc. Look below at images:







My 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  
for (int x = 0; x < tmap.getWidth(); x++) {
                    for (int y = 0; y < tmap.getHeight(); y++) {
                        //creats an image of the tile
                       Image tImg = tmap.getTileImage(x, y, layerIndex);
                        int tid = map.getTileId(x, y, layerIndex);
                        if (tImg != null) {
                            //load background as an image
                           if (property.equalsIgnoreCase("background")) {
                                StaticActor bg = new StaticActor(x * tImg.getWidth(), y * tImg.getHeight(), tImg.getWidth(), tImg.getHeight(), tImg);
                                bg.depth = -100;
                                add(bg);
                                //load the trees/benches etc as an image too
                           } else if (property.equalsIgnoreCase("entities")) {
                                StaticActor ents = new StaticActor(x * tImg.getWidth(), y * tImg.getHeight(), tImg.getWidth(), tImg.getHeight(), tImg);
                                ents.depth = -50;
                                add(ents);
                                //load all the victims/people
                           } else if (property.equalsIgnoreCase("victims")) {
                                //    String victim = map.getTileProperty(tid, "victim", null);

                                Man m = new Man(x * tImg.getWidth(), y * tImg.getHeight(), "man");
                                Man m2 = new Man(77, 79, "man"); //test man
                               add(m);
                                add(m2);
                                Log.debug("Man added");
                                //load the collision blocks
                           } else if (property.equalsIgnoreCase("collision")) {
                                CollisionEntity ce = new CollisionEntity(x * tImg.getWidth(), y * tImg.getHeight(), tmap.getTileWidth(), tmap.getTileHeight());
                                add(ce);
                            }
                        }
                    }
                }



Even if I don't add the background as an image and the trees and stuff as an image, and just use map.render(0,0) it does the same thing. If I use this code and not the map.render(0,0) does the same thing. Not sure what is wrong? Any way to get this working? Thanks
Offline h3ckboy
« Reply #1 - Posted 2011-11-27 18:50:21 »

sorry, I am a little confused, so if you resize the window does the area of activity (or whateve ru want to call it) resize with the window? or is it always the same.

if it is always the same, then look around for somewhere where you use the numbers instead of like GameWindow.getWidth().
Offline gbeebe

Senior Member


Medals: 5
Projects: 1



« Reply #2 - Posted 2011-11-27 19:39:27 »

What is the value of tmap.width?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Azulon

Senior Newbie


Medals: 1



« Reply #3 - Posted 2011-11-27 20:01:22 »

I'm not resizing the window. I am using a camera to move around the map. The width of the map is 100. But what is happening is when I start the game you see what your suppose to see in the first picture. But when I start moving around to the other parts of the map it shows the map but the entities and the collision blocks arent there when they should be.
Offline h3ckboy
« Reply #4 - Posted 2011-11-27 20:06:35 »

wait, what is the second picture then?
Offline Azulon

Senior Newbie


Medals: 1



« Reply #5 - Posted 2011-11-27 20:37:02 »

The second picture I just moved across the map a little bit by using translate(x,y). The picture is bigger for some reason, but the window size is still the same.
Offline Azulon

Senior Newbie


Medals: 1



« Reply #6 - Posted 2011-11-27 23:29:18 »

If I take away the map.render(0,0) from the render method, this is what I get.



It still renders the entities in that section to the right and the collision blocks, but not for the rest of the map.


EDIT:

I changed my code around and still get the same thing

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  
/**
     * Loads and reads the tiledmap and adds the collision layer to the map
     * @param map
     */

    private void createCollisionMap(TiledMap map) {
        for (int x = 0; x < map.getWidth(); x++) {
            for (int y = 0; y < map.getHeight(); y++) {
                Image tImg = map.getTileImage(x, y, 0);
                if (tImg != null) {
                    CollisionEntity ce = new CollisionEntity(x * tImg.getWidth(), y * tImg.getHeight(), map.getTileWidth(), map.getTileHeight());
                    add(ce);
                    System.out.println("add collission");
                }
            }
        }
    }

    /**
     * Loads and reads the tiledmap and adds the entities layer to the map
     * @param map
     */

    private void addEntities(TiledMap map) {
        for (int x = 0; x < map.getWidth(); x++) {
            for (int y = 0; y < map.getHeight(); y++) {
                int tileId = map.getTileId(x, y, 1);
                String value = map.getTileProperty(tileId, "victim", null);
                if ("man".equalsIgnoreCase(value)) {
                    Man m = new Man(x * 16, y * 16, "man");
                    m.depth = 100;
                    add(m);
                }
            }
        }
    }


This time it loads the entire map but doesn't make it an image like last time, but the same thing happens like in the second picture. Everything renders on the map, but the entities do not appear.
Offline Azulon

Senior Newbie


Medals: 1



« Reply #7 - Posted 2011-11-28 01:03:47 »

lol k fixed. Extremely dumb error. Noticed I was using my camera to set a certain area to render. Changed the variables and fixed the problem.
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.

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

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

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

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

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

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

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

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

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

CJLetsGame (203 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!