12 hours ago · Tech · 0 comments

A small improvement; a confession. I wind up thinking in public about how I live. CW: LLM-AI, Jesuitical Small Improvement Yesterday I was reading some Arcade documentation and discovered that I could change this: class BorderedText: def create_offset_text(self, dx, dy, color): text = arcade.Text(self.msg, self.base_x + dx, dy, color, font_size=self.font_size, batch=self.batch) text.x = text.x - text.content_width // 2 return text That code renders the text, gets its rendered width, and repositions it to center it. I found, in the documentation, that I could instead do this: def create_offset_text(self, dx, dy, color): text = Text(self.msg, self.base_x + dx, dy, color, anchor_x='center', font_size=self.font_size, batch=self.batch) return text The anchor_x tells the Text constructor to center the text. Much nicer and surely saves some kind of vertex updating nonsense. Confession I have to confess that I saw the trick of dividing the content width in half and moving the text origin in…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.