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

tdl.screenshot not working? #40

Closed
keytonw opened this issue May 26, 2018 · 3 comments
Closed

tdl.screenshot not working? #40

keytonw opened this issue May 26, 2018 · 3 comments
Assignees
Labels

Comments

@keytonw
Copy link

keytonw commented May 26, 2018

Trying to do a simple screenshot test. No bug but nothing happens. Do I need to initialized differently to get it to work?

import tdl

def handle_keys(user_input):
    # Movement keys
    if user_input.key == 'UP':
        return {'move': (0, -1)}
    elif user_input.key == 'DOWN':
        return {'move': (0, 1)}
    elif user_input.key == 'LEFT':
        return {'move': (-1, 0)}
    elif user_input.key == 'RIGHT':
        return {'move': (1, 0)}

    if user_input.key == 'ENTER' and user_input.alt:
        # Alt+Enter: toggle full screen
        return {'fullscreen': True}
    elif user_input.key == 'ESCAPE':
        # Exit the game
        return {'exit': True}

    # No key was pressed
    return {}

def main():
    screen_width = 80
    screen_height = 50
    player_x = int(screen_width / 2)
    player_y = int(screen_height / 2)

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(screen_width, screen_height, title='Roguelike Tutorial Revised', fullscreen=True)

    while not tdl.event.is_window_closed():
        root_console.draw_char(player_x, player_y, '@', bg=None, fg=(255, 255, 255))
        tdl.flush()

        root_console.draw_char(player_x, player_y, ' ', bg=None)

        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if not user_input:
            continue
        action = handle_keys(user_input)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            tdl.screenshot() ###############################
            dx, dy = move
            player_x += dx
            player_y += dy

        if exit:
            return True

        if fullscreen:
            tdl.set_fullscreen(not tdl.get_fullscreen())
            return True


if __name__ == "__main__":
    main()
@HexDecimal HexDecimal self-assigned this May 26, 2018
@HexDecimal HexDecimal added the bug label May 26, 2018
@HexDecimal
Copy link
Collaborator

I can confirm the bug exists in libtcod itself. The screenshot code is non-trivial, so it will take a little while to fix.

The bug seems to be limited to the SDL renderer, so if you add renderer='GLSL' to tdl.init you should able to take screenshots.

@keytonw
Copy link
Author

keytonw commented May 26, 2018

Thanks, Kyle. Confirmed that setting the renderer works like a charm. Appreciate the quick response! Have a good rest of your weekend...

@HexDecimal
Copy link
Collaborator

The regression in the old SDL renderer is fixed. You can now take screenshots with it active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants