So right now the problems are:
- Character image refuses to update its position
- Character can only go about 200 pixels and then it snaps back to its original position and sorta jiggles a little bit (not really clear in the .gif, but trust me it happens)
- Character needs to stand in the black outlined shape above (this can be solved probably by defining the character image's anchor, but I'm not really sure how to do that).
Can anyone help me figure out how to fix these things? Here's my code that I cobbled together with other code that I've seen:
Code: Select all
init:
image bg example = "bg/bgtestA.png"
python:
class TestDisplayable(renpy.Displayable):
def __init__(self):
renpy.Displayable.__init__(self)
# Displayables that we will use
self.player = Image ("char/playerexample.png")
# the sizes of images maybe?
self.PLAYER_WIDTH = 140
self.PLAYER_HEIGHT = 319
self.SCENE_LEFT = 248
self.SCENE_RIGHT = 1876
self.player_speed = 3
self.move_left = False
self.move_right = False
# Position of player
self.px = 250
self.py = 840
def visit(self):
return [ self.player ]
# OK, time to experiment a bit with renders
def render(self, width, height, st, at):
# The Render object we'll be drawing into.
r = renpy.Render(width, height)
player = renpy.displayable('char/playerexample.png')
player_r = renpy.render(player, 1920, 1080, 0, 0)
r.blit(player_r, (self.px, self.py))
# Determines the speed
if self.move_left:
self.px -= self.player_speed
elif self.move_right:
self.px += self.player_speed
# Ask that we be re-rendered ASAP, so we can show the next frame.
renpy.redraw(self, 0)
return r
# Handles events
def event(self, ev, x, y, st):
import pygame
# Keyboard controls
if ev.type == pygame.KEYDOWN:
if ev.key == pygame.K_LEFT:
self.move_left = True
self.move_right = False
elif ev.key == pygame.K_RIGHT:
self.move_right = True
self.move_left = False
elif ev.type == pygame.KEYUP:
if ev.key == pygame.K_LEFT:
self.move_left = False
elif ev.key == pygame.K_RIGHT:
self.move_right = False
else:
raise renpy.IgnoreEvent()
# Set the position of the player.
x = max(x, self.SCENE_RIGHT)
x = min(x, self.SCENE_LEFT)
self.px = x
label adventure_test:
window hide
scene bg example
window show
"Hey, are we even doing anything?"
window hide
pause
python:
ui.add(TestDisplayable())
ui.interact(suppress_overlay=True, suppress_underlay=True)
return