Problems with position of a custom displayable

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Queex
Regular
Posts: 46
Joined: Sat Mar 14, 2015 9:47 am
Contact:

Problems with position of a custom displayable

#1 Post by Queex »

I've defined a custom displayable with a number of child displayables arranged in a grid. It appears to render correctly. However, when trying to show it in the centre with 'truecenter' the bottom right-hand corner is placed in the centre. If it was the top left, I would assume that the width and height are not being picked up correctly, but bottom right is a puzzler. I'm not sure if it's a problem with the custom displayable, or the DynamicDisplayable I'm wrapping around it.

Code: Select all

image mapVision=DynamicDisplayable(show_map)

init python:

  def show_map(st, at):
    if map_centre==None:
      return Solid("#000"), None
    else:
      return MapDisplayable(map, map_centre), None

  class MapDisplayable(renpy.Displayable):
    def __init__(self, map, xypair, **kwargs):
      super(MapDisplayable,self).__init__(**kwargs)
      self.map=map
      self.centre=xypair
      self.children=[]
      self.width=11*48 # the tile grid fits within an 11x11 square of tiles, tiles are 48px square
      self.height=11*48

    def per_interact(self):
      self.children= (something quite complicated omitted for brevity)
      renpy.redraw(self,0)
      def render(self, width, height, at, st):
      render=renpy.Render(self.width,self.height)
      for ii in range(len(self.children)):
        render.blit(renpy.render(self.children[ii], self.children[ii].size, self.children[ii].size, st, at), (MapDisplayable.visible[ii][0]*48-24,MapDisplayable.visible[ii][1]*48-24)) # MapDisplayable.visible is an array of tuples that defines the offsets for the tiles to show
      return render

    def visit(self):
      return self.children
      
label start:
  $ map_centre=(3,3)
  show mapVision at truecenter
  "Start."
I don't know that the self.width and self.height actually do anything. I had a pick through the source code to see if I needed to replace any other member functions, but couldn't find where renpy.Displayable was defined. Also the search function on these forums doesn't seem to be working presently.

User avatar
Queex
Regular
Posts: 46
Joined: Sat Mar 14, 2015 9:47 am
Contact:

Re: Problems with position of a custom displayable

#2 Post by Queex »

Giving this a bump.

I can probably work around the problem by defining a new position that places it where I want it, but I suspect the underlying issue is something I'm doing wrong with these custom displayables and I'd prefer to find out what before I make too many more of them.

Post Reply

Who is online

Users browsing this forum: No registered users