Moving sprites with keyboard inputs

Forum organization and occasional community-building.
Forum rules
Questions about Ren'Py should go in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
Gonggrijp
Newbie
Posts: 4
Joined: Sun Aug 09, 2020 10:08 am
Completed: None (yet)
Projects: Bond of Heroes
Location: Belgium
Contact:

Moving sprites with keyboard inputs

#1 Post by Gonggrijp »

I'm creating an RPG visual novel, and I want the main character to move when I press a certain key on my keyboard. I've been looking all over the internet and nothing that I found really helped me. The problem isn't the moving of the character, but the problem is that I don't know how to make the game check for a button press. Could somebody help me?

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Moving sprites with keyboard inputs

#2 Post by drKlauz »

I did side-scroller in renpy, used custom displayable, in render method i polled keyboard and gamepad state and updated pc and camera positions.
Keyboard was polled by pygame.key.get_pressed() call - https://www.pygame.org/docs/ref/key.htm ... et_pressed

If you don't want to dive deep and don't need real-time movement i suggest simple adding keys to screen or even left/right imagebuttons.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

Gonggrijp
Newbie
Posts: 4
Joined: Sun Aug 09, 2020 10:08 am
Completed: None (yet)
Projects: Bond of Heroes
Location: Belgium
Contact:

Re: Moving sprites with keyboard inputs

#3 Post by Gonggrijp »

Thank you! You helped me a lot.

Just one more question: How do I import Pygame? (I’m completely new at python so I don’t know)

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: Moving sprites with keyboard inputs

#4 Post by drKlauz »

Code: Select all

init python:
  import pygame
After this pygame will be available to every rpy file. Keep in mind tho, this pygame is not exactly real pygame :D Some stuff may be missing, but for most use cases it is more than enough.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

Gonggrijp
Newbie
Posts: 4
Joined: Sun Aug 09, 2020 10:08 am
Completed: None (yet)
Projects: Bond of Heroes
Location: Belgium
Contact:

Re: Moving sprites with keyboard inputs

#5 Post by Gonggrijp »

Thank you so much! It works now!

Post Reply

Who is online

Users browsing this forum: No registered users