Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 1029 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!
Play the free demo of Revenge of the Titans!
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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
hobbles (6 views)
2013-05-22 00:54:55

cubemaster21 (74 views)
2013-05-17 21:29:12

alaslipknot (86 views)
2013-05-16 21:24:48

gouessej (115 views)
2013-05-16 00:53:38

gouessej (110 views)
2013-05-16 00:17:58

theagentd (121 views)
2013-05-15 15:01:13

theagentd (110 views)
2013-05-15 15:00:54

StreetDoggy (155 views)
2013-05-14 15:56:26

kutucuk (177 views)
2013-05-12 17:10:36

kutucuk (174 views)
2013-05-12 15:36:09
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.251 seconds with 20 queries.