Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprites #4

Closed
GaoZe36 opened this issue Jun 3, 2022 · 3 comments
Closed

Sprites #4

GaoZe36 opened this issue Jun 3, 2022 · 3 comments

Comments

@GaoZe36
Copy link

GaoZe36 commented Jun 3, 2022

Is it possible to hide certain sprites in a layer using something like setLayerVisablitybyName with changes made to it, or is it not possible?
Ex.
Player 1, Player 2, and Player 3
With advancing dialog, each player's screen shows the same thing, but only player 1 is visible, and player 2,3 is off-screen, with no name tag.
With something like "show Player 2" player 1 and 2 is visible, and player 3 is not.

@dbakewel
Copy link
Owner

dbakewel commented Jun 3, 2022

The game engine itself can't but you can add it yourself.

You can add a new property to sprite objects called 'visible' which contains a boolean (True or False). The property does not have to be in every sprite, but if it is and 'visible' == False then do not render the sprite.

To use this feature you just need to add 'visible' to any sprite you want to hide. For example, on the server in the ServerMap class, you could hide all players on the sprite layer like this (not tested so it may have some errors)

    for sprite in self['sprites']:
        if sprite['type'] == 'player':
            sprite['visible'] = False

Make them visible again using one the lines of code below:

sprite['visible'] = True
or
del sprite['visible']

Now the data is in place so now you need to use it. On the client look for 'visible' and do not render the sprite, it's label, or it's speechText. You could modify several methods on the ClientMap to do this or just remove thees sprites before the map is rendered. An easy way is to extend the blitMap() method of the ClientMap class so that is looks for 'visible' in the sprites and removes them. Keep in mind the the client gets a new list of sprites each step so we don't need to worry about putting them back. Something like this should work (again untested):

def blitMap(self, destImage, offset, sprites):
    """Extend blitMap() to remove sprites with 'visible' == False"""

   # fancy way to iterate over a list and modify it at the same time. This only keeps sprites that evaluate to True
   sprites = list(filter(lambda s: not ('visible' in s and s['visible'] == False), sprites))  

    # render the map as normal
    return super().blitMap(destImage, offset, sprites)

It this does not work please post the error and we can work it out.

@dbakewel
Copy link
Owner

dbakewel commented Jun 3, 2022

Also, if this works for you please let me know and also close this issue.

@GaoZe36
Copy link
Author

GaoZe36 commented Jun 3, 2022

Thank you soooo much!!! We were in desperate straits, but your timely message made so much sense. Today, we tried it and it was flawless. Absolutely flawless. You have our deepest gratitude! : )

Working with Lancaster has really taught us the intricacies of programming with Python, and we're so glad something like this exists. Please tell Ms. Wear you think we're cool B)

@GaoZe36 GaoZe36 closed this as completed Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants