Giter VIP home page Giter VIP logo

pyscroll's Introduction

pyscroll

For Python 3.9+ and pygame 2.0+

pygame-ce is supported

A simple and fast module for animated scrolling maps for your new or existing game.

If you find this useful, please consider making a donation to help support it https://liberapay.com/ltheden/donate

Discord! https://discord.gg/2taTP4aYR6

Introduction

pyscroll is a generic module for making a fast scrolling image with pygame. It uses a lot of magic to get great framerates out of pygame. It only exists to draw a map. It doesn't load images or data, so you can use your own custom data structures, tile storage, ect.

pyscroll is compatible with pytmx (https://github.com/bitcraft/pytmx), so you can use your Tiled maps. It also has out-of-the-box support for pygame sprites.

Features

  • Reload the map tiles and data without closing the game
  • Sprites or plain surfaces can be drawn in layers
  • Animated tiles
  • Zoom in and out
  • Includes optional drop-in replacement for pygame LayeredGroup
  • Pixel alpha and colorkey tilesets are supported
  • Drawing and scrolling shapes
  • Fast and small footprint
  • Speed is not affected by map size
  • Support for pytmx loaded maps from Tiled Map Editor

Use It Like a Camera

In order to further simplify using scrolling maps, pyscroll includes a pygame sprite group that will render all sprites on the map and will correctly draw them over or under tiles. Sprites can use their rect in world coordinates, and the group will work like a camera, translating world coordinates to screen coordinates while rendering sprites and map layers.

It's also useful to make minimaps or create simple chunky graphics.

Installation

Install from pip

pip install pyscroll

You can also manually install it from source

python setup.py install

New Game Tutorial

This is a quick guide on building a new game with pyscroll and pygame. It uses the PyscrollGroup for efficient rendering. You are free to use any other pygame techniques and functions.

Open apps/tutorial/quest.py for a gentle introduction to pyscroll and the PyscrollGroup for pygame. There are plenty of comments to get you started.

The Quest demo shows how you can use a pyscroll group for drawing, how to load maps with pytmx, and how pyscroll can quickly render layers. Moving under some tiles will cause the Hero to be covered.

The repo wiki has more in-depth explanations of the tutorial code, including one way to implement sprite animation. Be sure to check it out. Anyone is welcome to make additions or improvements.

https://github.com/bitcraft/pyscroll/wiki

Example Use with pytmx

pyscroll and pytmx can load your maps from Tiled and use your pygame sprites. The following is a very basic way to load a map onto the screen.

from pytmx.util_pygame import load_pygame
import pygame
import pyscroll


class Sprite(pygame.sprite.Sprite):
    """
    Simple Sprite class for on-screen things
    
    """
    def __init__(self, surface) -> None:
        self.image = surface
        self.rect = surface.get_rect()


# Load TMX data
tmx_data = load_pygame("desert.tmx")

# Make the scrolling layer
map_layer = pyscroll.BufferedRenderer(
    data=pyscroll.TiledMapData(tmx_data),
    size=(400,400),
)

# make the pygame SpriteGroup with a scrolling map
group = pyscroll.PyscrollGroup(map_layer=map_layer)

# Add sprite(s) to the group
surface = pygame.image.load("my_surface.png").convert_alpha()
sprite = Sprite(surface)
group.add(sprite)

# Center the camera on the sprite
group.center(sprite.rect.center)

# Draw map and sprites using the group
# Notice I did not `screen.fill` here!  Clearing the screen is not
# needed since the map will clear it when drawn
group.draw(screen)

Adapting Existing Games / Map Data

pyscroll can be used with existing map data, but you will have to create a class to interact with pyscroll or adapt your data handler. Try to make it follow the same API as the TiledMapData adapter and you should be fine.

Give pyscroll surface to layer into the map

pyscroll can use a list of surfaces and render them on the map, taking account their layer position.

map_layer = pyscroll.BufferedRenderer(map_data, map_size)

# just an example for clarity.  here's a made up game engine:

def game_engine_draw():
   surfaces = list()
   for game_object in my_game_engine:

      # pyscroll uses normal pygame surfaces.
      surface = game_object.get_surface()

      # pyscroll will draw surfaces in screen coordinates, so translate them
      # you need to use a rect to handle tiles that cover surfaces.
      rect = game_object.get_screen_rect()

      # the list called 'surfaces' is required for pyscroll
      # notice the layer.  this determines which layers the sprite will cover.
      # layer numbers higher than this will cover the surface
      surfaces.append((surface, rect, game_object.layer))

   # tell pyscroll to draw to the screen, and use the surfaces supplied
   map_layer.draw(screen, screen.get_rect(), surfaces)

FAQ

Why are tiles repeating while scrolling?

Pyscroll by default will not handle maps that are not completely filled with tiles. This is in consideration of drawing speed. To clarify, you can have several layers, some layers without tiles, and that is fine; the problem is when there are empty spaces in all the layers, leaving gaps in the entire map. There are two ways to fix this issue with the 1st solution being the best performance wise:

1. In Tiled (or your data), fill in the empty spots with a tile

For best performance, you must have a tile in each part of the map. You can create a simple background layer, and fill with single color tiles where there are gaps. Pyscroll is very fast even with several layers, so there is virtually no penalty.

2. Pass "alpha=True" to the BufferedRenderer constructor.

All internal buffers will now support 'per-pixel alpha' and the areas without tiles will be fully transparent. You may still have graphical oddities depending on if you clear the screen or not, so you may have to experiment here. Since per-pixel alpha buffers are used, overall performance will be reduced by about 33%

Why are there obvious/ugly 'streaks' when scrolling?

Streaks are caused by missing tiles. See the above answer for solutions.

Can I blit anything 'under' the scrolling map layer?

Yes! There are two ways to handle this situation...both are experimental, but should work. These options will cause the renderer to do more housekeeping, actively clearing empty spaces in the buffer, so overall performance will be reduced.

1. Pass "alpha=True" to the constructor.

When drawing the screen, first blit what you want to be under the map (like a background, or parallax layer), then draw the pyscroll renderer or group. Since per-pixel alpha buffers are used, overall performance will be reduced.

2. Set a colorkey.

Pass "colorkey=theColorYouWant" to the BufferedRenderer constructor. In theory, you can now blit the map layer over other surfaces with transparency, but beware that it will produce some nasty side effects:

  1. Overall, performance will be reduced, as empty ares are being filled.
  2. If mixing 'per-pixel alpha' tilesets, tile edges may show the colorkey.

Does the map layer support transparency?

Yes...and no. By default, pyscroll handles all transparency types very well for the tiles and you should not have issues with that. However, if you are trying to blit/draw the map over existing graphics and "see through" transparent areas under the map, then you will have to use the "alpha", or "colorkey" methods described above.

Does pyscroll support parallax layers?

Not directly. However, you can build you own parallax effects by passing "alpha=True" to the BufferedRenderer constructor and using one renderer for each layer. Then it is just a matter of scrolling at different speeds.

pyscroll's People

Contributors

ambv avatar bitcraft avatar bluefish2020 avatar glyph avatar jaskrendix avatar kerizane avatar raiyankamal avatar t-persson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyscroll's Issues

pygame.error: cannot convert without pygame.display initialized

Hi,

Forgive me if this is user error but I'm trying to use pyscroll with a pre-existing game. Doing the bare minimum of the following:

self._map = load_pygame(self.tmx_file)
self.map_data_for_camera = pyscroll.TiledMapData(self._map)
Causes the following trace:

Traceback (most recent call last):
File "./run.py", line 4, in
import src.environment as environment
File "/home/joe/code/me/mr-figs/src/environment.py", line 40, in
level_obj_list = create_level_list()
File "/home/joe/code/me/mr-figs/src/environment.py", line 18, in create_level_list
level_dict[levels.level1.KEY_NAME] = level_base.LevelBase(levels.level1.LOCATION, 'NoNextScene', 1)
File "/home/joe/code/me/mr-figs/src/scenes/levelbase.py", line 22, in init
self.tiled_level = level_editor.LevelData(file)
File "/home/joe/code/me/mr-figs/src/level_editor.py", line 22, in init
self._map = load_pygame(self.tmx_file)
File "/home/joe/.local/lib/python3.6/site-packages/pytmx/util_pygame.py", line 144, in load_pygame
return pytmx.TiledMap(filename, *args, **kwargs)
File "/home/joe/.local/lib/python3.6/site-packages/pytmx/pytmx.py", line 354, in init
self.parse_xml(ElementTree.parse(self.filename).getroot())
File "/home/joe/.local/lib/python3.6/site-packages/pytmx/pytmx.py", line 417, in parse_xml
self.reload_images()
File "/home/joe/.local/lib/python3.6/site-packages/pytmx/pytmx.py", line 465, in reload_images
self.images[gid] = loader(rect, flags)
File "/home/joe/.local/lib/python3.6/site-packages/pytmx/util_pygame.py", line 118, in load_image
tile = smart_convert(tile, colorkey, pixelalpha)
File "/home/joe/.local/lib/python3.6/site-packages/pytmx/util_pygame.py", line 59, in smart_convert
tile = original.convert()
pygame.error: cannot convert without pygame.display initialized

I have already initialised the pygame display long ago and have also tried forcing it with pygame.display.init() to no avail.
For the record, the self.tmx_file is a valid tmx file. I have been using your pytmx library for a while with success but I'm having issues with pyscroll.

Thanks for the help, let me know if you need more info!

Edit: I'm on pygame 2 though I don't think that affects this.

Tiles drawn incorrectly on right side of screen

I created my own file called 'mygame.py' which is basically the same file as 'code/quest.py'. The only things that I changed were the tilemap files and a few other variables. The tilemap that I am using has two custom properties called start_tile_x/y. I use those values to determine the start location of the hero instead of putting him directly in the middle of the screen. Also, I set the window size to be the same dimensions as the tilemap file that I'm using.

When running the program, I move the hero to the right side of the screen but the map doesn't update properly. And it's just on the right portion of the tilemap (to the right of the cliff).
v0.02.zip

Querying pyscroll for a sprite's position?

Hello again!

I'm wanting to add in a basic lighting system into my game. The gist of it is that I want certain tiles to be illuminated. The problem comes with rendering the light at that tiles position. After pyscroll has done its zooming and possibly scrolling, the rect's x and y that I am querying are incorrect.

Here is some code that I'm working with to give you an idea:

def render_lights(self):
        self.veil.fill((50,50,50,155))

        # light_sources is just a slice of some of the sprites out of a PyscrollGroup
        for light_source in self.light_sources:
            light = pygame.image.load('./data/light-soft.png')
            self.veil.blit(
                light, 
                (
                    light_source.rect.x,
                    light_source.rect.y
                )
            )

        #To debug, remove the special_flags arg
        # needs blend_mult flag to work
        self.game_area.blit(self.veil, (0,0), )

I basically need to pin the light source to the tile but since the tiles can (and do) scroll, I was wondering what methods are available (if any) to do this?

Thanks again!

test_pyscroll Unit tests are failing

The tests in the tests/unittests/test_pyscroll.py file seems to be outdated. Running the tests results in an error.

$ python -m unittest tests.unittests.test_pyscroll
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
EEEE
======================================================================
ERROR: test_queue_bottom (tests.unittests.test_pyscroll.TestTileQueue)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/pyscroll/tests/unittests/test_pyscroll.py", line 49, in test_queue_bottom
    self.queue(self.mock, 0, 1)
  File "/pyscroll/pyscroll/orthographic.py", line 420, in _queue_edge_tiles
    append((v.left, v.bottom - 1, v.width, dy))
  File "/pyscroll/pyscroll/orthographic.py", line 410, in append
    self._clear_surface(self._buffer, ((rect[0] - v.left) * tw, (rect[1] - v.top) * th,
AttributeError: 'DummyBufferer' object has no attribute '_clear_surface'

======================================================================

The next three tests will abort with the same error.

----------------------------------------------------------------------
Ran 4 tests in 0.001s

FAILED (errors=4)

After adding a _clear_surface function to the DummyBuffer, each test case will fail with the following error:

Traceback (most recent call last):
  File "/pyscroll/tests/unittests/test_pyscroll.py", line 51, in test_queue_bottom
    self.verify_queue({(2, 3), (3, 3)})
  File "/pyscroll/tests/unittests/test_pyscroll.py", line 34, in verify_queue
    queue = {i[:2] for i in self.mock._tile_queue}
  File "/pyscroll/tests/unittests/test_pyscroll.py", line 34, in <setcomp>
    queue = {i[:2] for i in self.mock._tile_queue}
  File "/pyscroll/pyscroll/data.py", line 275, in get_tile_images_by_rect
    tile = self.get_tile_image(x, y, layer)
TypeError: get_tile_image() takes 2 positional arguments but 4 were given

Am I holding it wrong or should the tests be updated? Thanks a lot.

Pygame 2 and tutorial tile alpha support

I'm a beginner in terms of pygame so I can't tell if this is something easy or tricky to fix. I noticed that the quest tutorial project doesn't render alpha correctly for some of the tiles (but not all, see the lakes for example).

Screenshot 2020-11-02 at 14 26 21

Do you know what needs to change for this to look correctly with pygame 2.0?

Jump physics/collision detection

My collision detection is not working properly. In the update function, I go through the loop from the original code to detect collisions. That part is easy. The hard part is throwing in physics. The jump function itself is really quite simple, but trying to figure out all the cases and code them properly has proven to be a pain.

I'm not sure exactly how to move forward, but I just can't seem to figure this out. Some fresh eyes would be great.

v0.02.zip

Tiles with opacity that overlap sprites render darker

pyscroll is always drawing all layers on the first fill of the buffer. that includes layers that would normally be over a sprite. when the sprites are drawn, the buffer is drawn on the screen, then the sprites, then there is a collision check to see what sprites are under a layer...then overlapping tiles from the upper layers are drawn again.
so in this case, pyscroll needs to be aware of upper layers that have partial transparency, then instead of drawing only the top layer, it needs to clear the buffer, draw all the lower layers, the sprites, then the upper layers

Tutorial: pytmx module doesn't have "load_pygame"

Hello,

I just downloaded both the latest (in master) versions of pyscroll and pytmux. Unfortunately when I tried running the tutorial code I received the following error:

Traceback (most recent call last):
  File "quest.py", line 229, in <module>
    game = QuestGame()
  File "quest.py", line 107, in __init__
    tmx_data = pytmx.load_pygame(self.filename)
AttributeError: 'module' object has no attribute 'load_pygame'

Any ideas what I'm doing wrong?

Thanks!

How to connect/render multiple maps dynamically

I'd like to build a game with a endless scroll map, I've built several map sections with TileMapEditor, but I dont know how to connect these sections while the game is running. when a section is at an end, I wanna randomly pickup a new section and join in without pause. can pyscroll do it?

KeyError: 'path'

I'm running Python 3.7 on Linux and I get the following error when trying to run Quest.py. I'm running it from within a Pycharm project I've created. I've also tried outside Pycharm from a shell. I extracted the files from the downloaded zip from GitHub but did not keep the same root directory. Can't see why that would matter looking at the code. Any ideas?

Traceback (most recent call last):
File "/home/xxx/data/pycharm/xxx/tutorial/quest.py", line 240, in
game = QuestGame()
File "/home/xxx/data/pycharm/xxx/tutorial/quest.py", line 109, in init
tmx_data = load_pygame(self.filename)
File "/home/xxx/.virtualenvs/xxx/lib/python3.7/site-packages/pytmx/util_pygame.py", line 141, in load_pygame
return pytmx.TiledMap(filename, *args, **kwargs)
File "/home/xxx/.virtualenvs/xxx/lib/python3.7/site-packages/pytmx/pytmx.py", line 360, in init
self.parse_xml(ElementTree.parse(self.filename).getroot())
File "/home/xxx/.virtualenvs/xxx/lib/python3.7/site-packages/pytmx/pytmx.py", line 400, in parse_xml
self.add_tileset(TiledTileset(self, subnode))
File "/home/xxx/.virtualenvs/xxx/lib/python3.7/site-packages/pytmx/pytmx.py", line 845, in init
self.parse_xml(node)
File "/home/xxx/.virtualenvs/xxx/lib/python3.7/site-packages/pytmx/pytmx.py", line 894, in parse_xml
p["path"] = os.path.join(os.path.dirname(source), p["path"])
KeyError: 'path'

Not sure if pytmx or pyscroll error

After following the tutorial to add in pyscroll to work with pytmx, I've gotten the following error.

pyscroll error

I also get the same error running the demo from your tutorial.

DirtySprite in Pyscrollgroup is rendered but blendmode is being ignored

Ahoi again, this time i'm having a little trouble adding fog of exploration.
It might be me doing things wrong again, but to illustrate, this is what i'm trying:

self.fog = pygame.sprite.DirtySprite()
self.fog.blendmode = pygame.BLEND_RGBA_MIN
self.fog.rect = pygame.Rect([0,0,self.render_size[0], self.render_size[1]])
self.fog.image = pygame.Surface([self.map_data.map_size[0]_self.map_data.tile_size[0], self.map_data.map_size[1]_self.map_data.tile_size[1]]).convert_alpha()
self.fog.image.fill((0,0,0, 255))
self.mapgroup.add(self.fog, layer=15)

I can now fill nice faded circles around the actor position and get an added non-transparent surface with the fog "seemingly lifted correctly".
Seems to me like the blendmode i set in the sprite is ignored.

Can't get lighting going correctly

My idea is:

  1. Have an object group in the map with lights
  2. Render the map to a surface
  3. Fill a same-size surface with black, adjust transparency depending on daylight
  4. Draw and blit the light objects (simple filled white circle pngs) on the the daylight-surface
  5. Multiply-blit the resulting compound light surface onto the map rendering

But i can't get the rendering of only the light objects needed in step 4.
I tried adding another group but it always renders the other layers, too, which obviously gives bad results.
So, i'm looking for a way to render a group with only one specific (lights) object layer to a seperate surface. Is that possible? Or is there a better way to get proper lighting into the game?

Animated character images.

I doubt this is the place to ask for help but I couldn't find any way to contact you otherwise.

I recently began writing a top-down 2D RPG game using PyTMX and PyScroll. Most(if not all) of my code is your example code, so I thought you would be best to help me.

My main problem is that your code doesn't blit the character image to the screen, instead it renders it as part of the display(I think), this method does not allow quick switching of the image which is needed for animation.

View my repo here: https://github.com/Connor124/Gran-Theft-Crop-Toe

PS: I'm on Debian 9, Running Python3.5.2

not-animated tiles with custom properties

Hi,
I'm using pyscroll for my game and installed a newer version via pip.
My current pyscroll version is now 2.16.2 for Python 2.7

The tutorial quest starts fine. But if I add (for example) in grasslands.tmx some random property to a not-animated tile and use this tile on the map, I'm getting the following error by starting quest.py:

Traceback (most recent call last):
  File "...\pyscroll\tutorial\code\quest.py", line 234, in <module>
    game = QuestGame()
  File "...\pyscroll\tutorial\code\quest.py", line 123, in __init__
    self.map_layer = pyscroll.BufferedRenderer(map_data, screen.get_size())
  File "...\pyscroll\pyscroll\orthographic.py", line 71, in __init__
    self.reload_animations()
  File "...\pyscroll\pyscroll\orthographic.py", line 360, in reload_animations
    ani = AnimationToken(gid, frames)
  File "...\pyscroll\pyscroll\animation.py", line 13, in __init__
    self.next = frames[0].duration
IndexError: tuple index out of range

Group draw method is inefficient

You could drastically improve the draw method if you only drew the sprites that are on screen.
Even manually removing the sprites that are off screen from the pyscroll group then adding them back in if they are on screen each clock cycle results in a 20FPS improvement in my game. But if such a function were built in it would run way better and it really wouln't be that hard to add.

Isometric support

I'm going to add experimental isometric support in a new branch. I'll be commiting the changes later this week. Please watch the readme in the branch, and add any issues that you find.

pyscroll uses many hacks to get good framerates for orthogonal maps and they don't directly translate well to isometric rendering, so there will be many features missing until i find new creative ways to render quickly.

Keep an eye out on the readme, I will keep notes there that relate to it.

Thanks!

Converting a tile to an in-game sprite?

Hi,

I'm implementing pyscroll into my game and I'm having an issue with pyscroll immediately rendering out the entire map (which I expect). My question is, how do I convert this image into something usable for my game?

I have some sprite classes that I want to assign each tile to, I could do this with LayeredUpdates quite easily, literally just a call to add and then draw and it would work. Previously, I used pygame's LayeredUpdates and just called draw on the group and it would render everything out. But, if I do that with the PyscrollGroup, it renders those sprites on top of the map that pyscroll has also rendered.

Ideally what I'd do is just loop through all the tiles that have been made via pytmx/pyscroll (I'm using both), create the correct objects for them and then add those to the PyscrollGroup to be rendered out.

Happy to clarify a bit more, not sure I was too coherent 😄

Here's a gif to demonstrate what I mean, notice how the 'bombs' stay there (and the rocks too)? That's because of the map layer (I think). I need to convert the tiles in the map layer to the ones I have defined in my game, I've looked at some examples but couldn't find anything that addresses this.

For the record here's what it looked like before trying I started trying to implement pyscroll

Thanks for the help!

edit: I'm also open to hiding what pyscroll renders out and just having the camera follow the player, whatever works really

BufferedRenderer is slower when zoomed.

I noticed quest.py spends a lot of time in pygame.transform.scale. When I removed the zoom from BufferedRenderer I went from ~70 fps to ~90 fps. Maybe it would be possible to save the zoomed surface rather than scale it every loop. You should be able to notice the issue if you run python -m cProfile -s time quest.py from the command prompt. The specific line is here.

Proper sprite animation?

With the demo you just a sprite moving around. Right now I have my sprite animated using http://inventwithpython.com/pyganim/

I was wondering how I could modify pyscroll to work with that. I have the map displaying but it is not centered on the player nor will it scroll due to how I have the sprite set up for animation. Any suggestions or thoughts would be great.

Orthographic renderer not rendering alpha with camera clamp turned off

Tried basic example to get a hang of it and found that this:

map_layer = BufferedRenderer(map_data, viewport.size, alpha=True, clamp_camera=False, tall_sprites=1)
camera = PyscrollGroup(map_layer=map_layer, default_layer=2)
camera.center(viewport.center)

gives me this:

example

As you can see the background is supposed to be blue but the buffer looses its alpha channel somewhere.
It works if I clamp the camera.

Problem with memory and PyscrollGroup

Inside the pygame AbstractGroup there is a list which stores all removed sprites.
This list is cleared in the "draw" call of the pygame Group.

However, inside the PyscrollGroup which inherits and overrides the "draw" method, this list is never cleared. This will cause problems if you add and remove sprites to the group, as memory usage will constantly increase.

Attached zip file has a program (python3) which will reproduce the problem. In the file added we redraw a sprite every iteration of the main loop and it will print the time it takes to clear sprites every 5s.
This is of course a worst case scenario, but if you're utilizing the PyscrollGroup for a long time, then I can see the program running slower and slower as the list increases.

reproduce.zip

hit an error in both branch iso and master

Traceback (most recent call last):
File "main.py", line 96, in
game.main()
File "main.py", line 85, in main
self.update(dt)
File "main.py", line 55, in update
self.levelGroup.update(dt)
File "/home/jauria/Proyectos/IsoGame/pyscroll/util.py", line 90, in update
pygame.sprite.LayeredUpdates.update(self, dt)
File "/usr/lib/python2.7/dist-packages/pygame/sprite.py", line 399, in update
for s in self.sprites(): s.update(*args)
TypeError: update() takes exactly 1 argument (2 given)

got this error in windows xp (Master branch) and linux (Isometric branch)

not sure if a bug or my fault
thx

Animated tiles seem to just stack frames, instead of circling through them

Animated tiles seem like they are just drawing each frame on top of the previous, without clearing the image.

I'm attaching a test Tiled map: test.zip, that I tested with demo.py

The flag animation has three frames: one with a blue flag, another with a red flag, and the third just the pole. Blue and red bits are always visible, and you never get the sole pole. The animation displays fine in Tiled (v1.3.3).

Tutorial for animated maps with custom map data

It's currently a little unclear what is required to implement/modify to enable animated maps for custom map data. Especially the relationship to AnimationToken.

For static maps, it's straightforward to just hijack _get_tile_image and it works nicely.

pygame2 rendered support

Just wondering if bitcraft or anyone else is still interesting in pyscroll and if it might be ported to pygame2. I've already gotten pytmx to load images into textured images for the renderer, but porting pyscroll looks a bit harder. I don't want to try that until the final pygame2 renderer API is documented.

non-integer zoom has weird rendering

I haven't looked at the code but setting the zoom to something like 1.01 will create this weird black mask in empty tiles.

Also the scale of zoom 1 is vastly different from 1.01 and 0.99

TypeError: 'type' object is not subscriptable

Using the latest release or the master branch I get aTypeError just importing pyscroll:

$ python --version
Python 3.8.10

Traceback:

======================================================================
ERROR: pyscroll (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: pyscroll
Traceback (most recent call last):
  File "/usr/lib64/python3.8/unittest/loader.py", line 470, in _find_test_path
    package = self._get_module_from_name(name)
  File "/usr/lib64/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/nuno/Dev/Python/pyscroll/pyscroll/__init__.py", line 2, in <module>
    from .orthographic import BufferedRenderer
  File "/home/nuno/Dev/Python/pyscroll/pyscroll/orthographic.py", line 11, in <module>
    from .common import surface_clipping_context, RectLike
  File "/home/nuno/Dev/Python/pyscroll/pyscroll/common.py", line 6, in <module>
    RectLike = Union[Rect, tuple[Any, Any, Any, Any]]
TypeError: 'type' object is not subscriptable


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
Test failed: <unittest.runner.TextTestResult run=1 errors=1 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=1 errors=1 failures=0>

Scaling algorithm?

Hi again,

I see that you use pygame.transform.scale (usually) as the function for scaling sprites in/out. What is the process you use to determine how much to scale in by depending on screen size? The reason I ask is because I have some other scenes (main menus, credits etc...) that are not in the PyscrollGroup and therefore aren't using the same scaling. I'd like it to be consistent so I'd like to replicate how you are doing it where possible.

My game is orthographic :)

Thanks!

Sprite scale clamping

It would be great to have a way to limit sprite scaling. At the moment I have situations where I want to zoom out, and it all works very well except that sprites get very small. If I could just clamp the maximum scale for the sprite scaling that would great. Similarly zooming in a lot.

Unfortunately it seems like the scaling is applied to the final surface, so it would be a bit of an overhaul to change it.

However, it does strike me that there is an opportunity, in that the scaling of map tiles shouldn't be repeatedly happening anyway?

Even thoughts on achieving this. Thanks for pyscroll :)

pygame v. pygame-ce

setuptools cannot currently handle the situation where a package will support one of a set of packages, such as "either pygame or pygame-ce are a dependency". to support pygame-ce, im (hopefully) temporally removing pygame from setup.py so that pygame-ce can be installed with pyscroll. when setuptools supports this situation, we can add it back to install_requires.

Issue with map having extra tiles it shouldn't

Hey,

I am not sure if this is an issue with my code, pygame, PyTMX, or pyscroll so sorry if this is the incorrect place for this.

When I place a tile in my level, using tiled, and then import it into the game if the tile started off the screen and then comes into the screen it seems to get repeated forever in the direction it came from.

Here is a screen shot to show what I mean. The player spawns the the left with the second row of red tile off the screen to the right. As the tile comes into the screen it appears to be repeated.
image

Here is a screen shot of how the level looks in Tiled. I have confirmed the XML is correct as well.
image

You can see my code here: https://github.com/Regner/ludumdare34

Any help would be greatly appreciated. :)

Sorting with sprites on same y coord is incorrect

image
probably not a common situation, but the stump tiles are aligned with the sprite on the bottom edge. when sorted, their b (bottom) values are the same, so then they are sorted by the x value, so the stump on the right is drawn after the sprite.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.