rendering a tiledmap including an Objects layer

23 views
Skip to first unread message

Paolo

unread,
Mar 20, 2014, 8:58:11 AM3/20/14
to gummw...@googlegroups.com
Hello,
thank you for your great work.
I am trying to use your library with maps containing objects layer (like the free maps set included in The Mana World).
I found that I can easy draw the maps using the function  "toolkit.draw_object_array(self.visible_objects)"
But when I try to render the same maps with BasicMapRenderer methods, I get this error: "blit(sprite.image, (sx-cx,sy-cy)) TypeError: argument 1 must be pygame.Surface, not None"
To avoid this error I have to remove the object layer from the loaded map, and after that everything works.

I can't understand what is wrong with objects.

Paolo

bw

unread,
Mar 20, 2014, 5:53:20 PM3/20/14
to gummw...@googlegroups.com
Hi, Paolo,

Sorry you are having this issue. When I try example 07 with a TMW map I see the same issue.

It could take a while to debug the map and figure out exactly why this occurs, and whether the proper time to handle this may be during loading or rendering.

In the meantime you may try this. I was able to work around the issue by hacking the gummworld2.basicmaprenderer module in a couple places to skip tile objects that have no image.

In class BasicMapRenderer.draw_tiles:

        for tile in self._visible_tiles:
            im = tile.image
            r = tile.rect
            if im and colliderect(r):
                blit(im, r.move(-x, -y))

In class BasicMapRendererTile.__init__:

        for sprites in visible_objects:
            for sprite in sprites:
                im = sprite.image
                if im:
                    rect = sprite.rect
                    sx,sy = rect.topleft
                    blit(im, (sx-cx,sy-cy))

Cheers,

Gumm
--
You received this message because you are subscribed to the Google Groups "Gummworld2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gummworld2+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paolo

unread,
Mar 21, 2014, 4:02:55 AM3/21/14
to gummw...@googlegroups.com
Thank you for your kindly answer.
Yesterday in the process of improving my knowledge of gummworld2 I found the same solution you propose. The underlaying problem is the fact that normally objects are sprites without image, so it is impossible to blit them on the screen, but the solution is simply to avoid to do it creating a separate list of objects to treat for collision detection.

Another question I have regards the method, toolkit.draw_object_array.
I can use toolkit.draw_objetc only to render the portion of map which is included in the window widht and height. Is this a normal or am I missing the correct way to update the rect is rendered by toolkit.draw? By the way using the other method, BasicMapRenderer everything goes well using the method "renderer.set_rect"...


bw

unread,
Mar 22, 2014, 10:13:28 PM3/22/14
to gummw...@googlegroups.com
Hello again,

Giving this some more thought I began to realize that using the BasicMapRenderer with a map like those in The Mana World would not be very straightforward. I began remembering the complexity of multi-layered maps from our Pyweek team entries. You have to understand a bit about Tiled, and add some custom code for dealing with the special aspects of the layers: ground, obstacles, overlays, and an object layer.

I decided to write another demo, which you can get here:
http://code.google.com/p/gummworld2/source/browse/branches/tiled2/examples/07_tiled_tmw_with_renderer.py.

I marked the important parts with ## comments.

From this experience I also realized the renderer is pretty crude and limited in a 2.5D application. For this use it is only sufficient for ground tiles, but it still saves some much needed CPU cycles.

Cheers,

Gumm

bw

unread,
Mar 22, 2014, 10:39:51 PM3/22/14
to gummw...@googlegroups.com
Sorry, I forgot you asked a question.

If I understand the question correctly then, yes, toolkit.draw_object_array purposely culls (i.e. does not blit) the tiles that aren't visible in the screen area.

In order to position the camera over the section of map you wish to blit, use:

State.camera.position = x,y

Basically the camera represents the screen, unless you tell it to use a subsurface. The camera anchor (position) is the camera rect's center, and x,y is in map coordinates. It helps me to picture the map as a very large rect, and the camera as a smaller rect that moves around inside the map.


Gumm

On 3/21/2014 01:02, Paolo wrote:

Paolo

unread,
Mar 23, 2014, 6:40:02 AM3/23/14
to gummw...@googlegroups.com
Thank you again, I am working hard to understand the details of your library.

By the way the reason because I am trying to learn pygame programming is to realize a game with my son.

We have a first plot here where you can have an idea of the problems we have to solve using your library:
 https://code.google.com/p/pygame-game-test/source/browse/plot.txt
Do you think is possible to reach this type of complexity with your engine library?

Paolo

bw

unread,
Mar 23, 2014, 3:52:01 PM3/23/14
to gummw...@googlegroups.com
Egads, what a dark premise--war kills all but a few dirt-poor survivors who are extorted by a bloodthirsty tyrant. =o Notwithstanding, I'm fairly confident the mechanics of such a game could be done in Gummworld2, whether it's 2D or 2.5D. The difficulty (and fun, in my opinion) is that you will have to invent all of the game logic and player interface. You may have seen the games listed under Spotlight on the google code site which shows completed project types: board game, platformer, 2.5D action-adventure.

If you're just starting with Python and pygame, I highly recommend looking at Retro Game Library by PyMike. Gummworld2's world-vs-camera concept was taken from this. I have played with this one. It is a solid, complete and very simple library, and a superb learning environment for a first game; very easy to use, and very easy to look under the hood and see how PyMike did it. Even if you do not want your game to be a platformer, completing just one tiny "quest" with this library would be a great exercise for learning the nuts and bolts of a scrolling game.

If your game concept is more of a dialog-drama-RPG you might want to have a look at RenPy. It is a complete framework that lets one focus on content rather than the logic, mechanics, and interface. I have not played with this one, but it is quite popular.

If you're really attracted to Tiled as a map editor, you can see all the Tiled-tagged pygame projects here. There you will see:

Tiled TMX Loader by DR0ID which is used by Gummworld2. DR0ID's library has a built-in renderer, and a very nice demo that could be turned into a game. This library gets the programmer a bit closer to pygame.

mh by bitcraft, which is similar to Gummworld2. bitcraft and I began working on our projects about the same time. I have not played with this one.

I'm not attempting to persuade you in any fashion. Only opening up broader options from which to choose and learn.

Gumm

bw

unread,
Mar 23, 2014, 3:58:02 PM3/23/14
to Gummworld2
Whoops! Sorry for an error. (I corrected this inline, in the original email text below.)

Summary of my mistakes:

DR0ID's Tiled loader is map loader for Tiled. This is actually a newer version than Gummword2 presently has.

Tiled TMX Loader is bitcraft's Tiled loader, which I believe is included in his mh library.

Gumm


-------- Original Message --------
Subject: Re: [Gummworld2: 74] Re: rendering a tiledmap including an Objects layer
Date: Sun, 23 Mar 2014 12:52:01 -0700
From: bw <stabbin...@gmail.com>
To: gummw...@googlegroups.com


Egads, what a dark premise--war kills all but a few dirt-poor survivors who are extorted by a bloodthirsty tyrant. =o Notwithstanding, I'm fairly confident the mechanics of such a game could be done in Gummworld2, whether it's 2D or 2.5D. The difficulty (and fun, in my opinion) is that you will have to invent all of the game logic and player interface. You may have seen the games listed under Spotlight on the google code site which shows completed project types: board game, platformer, 2.5D action-adventure.

If you're just starting with Python and pygame, I highly recommend looking at Retro Game Library by PyMike. Gummworld2's world-vs-camera concept was taken from this. I have played with this one. It is a solid, complete and very simple library, and a superb learning environment for a first game; very easy to use, and very easy to look under the hood and see how PyMike did it. Even if you do not want your game to be a platformer, completing just one tiny "quest" with this library would be a great exercise for learning the nuts and bolts of a scrolling game.

If your game concept is more of a dialog-drama-RPG you might want to have a look at RenPy. It is a complete framework that lets one focus on content rather than the logic, mechanics, and interface. I have not played with this one, but it is quite popular.

If you're really attracted to Tiled as a map editor, you can see all the Tiled-tagged pygame projects here. There you will see:

map loader for Tiled by DR0ID  which is used by Gummworld2. DR0ID's library has a built-in renderer, and a very nice demo that could be turned into a game. This library gets the programmer a bit closer to pygame.

Paolo

unread,
Mar 23, 2014, 4:05:47 PM3/23/14
to gummw...@googlegroups.com
Ok, thank you very much for your hints and for the fact that you consider the game proposed by my son can be done with gumworld2 library.
My son is very excited by the mere idea to have game designed by himself and I have to try to give him something minimal working (I will put it on line soon).

By the way I am now trying to test your new demo 07_tiled_tmw_with_renderer.py and I get this error
"TypeError: 'NoneType' object is not callable" at line 265 with the instruction "camera.surface.blit(s.image, s.rect.move(camera.anti_interp(s)))"

bw

unread,
Mar 23, 2014, 9:05:14 PM3/23/14
to gummw...@googlegroups.com
Hm. I do not know how you got that. Both revisions in the repo have the following:

blit
(s.image, s.rect.move(camera.anti_interp(s)))

I may need you to post a bug report to the project. Include a zip of all files (gummworld2/ directory) that I need to run it.
Gumm
Reply all
Reply to author
Forward
0 new messages