#๐Ÿ”’ Entitys rendering ontop of other

5 messages ยท Page 1 of 1 (latest)

stable tinsel
#

Im using Ursina to try and make a little idle clicker game but the background sprites I made with

background2 = Entity(position=(2, 0, 0), scale=11, color=color.blue, model='quad')
background1 = Entity(position=(-2, 0, 0), scale=11, color=color.green, model='quad')

get created before the Tile object,

class Tile(Button):
    def __init__(self, position=(0, 0), tile_type="", status="", contents="", **kwargs):
        super().__init__(
            parent=scene,
            model='quad',
            color=color.azure,
            texture='lib/grass.png',
            highlight_color=color.red,
            position=position,
            **kwargs
        )
        self.tile_type = tile_type
        self.status = status
        self.contents = contents

        if self.tile_type == "sell":
            self.color = color.green

    def on_click(self):
        global selected_tile
        selected_tile = self
        print(f'Tile at {self.position} clicked!')
        self.color = color.red

    def update(self):
        global selected_tile

        if selected_tile != self:
            if self.tile_type == "sell":
                self.color = color.green
            else: self.color = color.azure

but only when I change the color in the code, with the current colors its fine but if I try to set it to brown it doesnt work. Whole program in next message.

trim hemlockBOT
#

@stable tinsel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

stable tinsel
#
from ursina import *
import json
import os

app = Ursina()

background2 = Entity(position=(2, 0, 0), scale=11, color=color.blue, model='quad')
background1 = Entity(position=(-2, 0, 0), scale=11, color=color.green, model='quad')

selected_tile = None

tiles = []

class Tile(Button):
    def __init__(self, position=(0, 0), tile_type="", status="", contents="", **kwargs):
        super().__init__(
            parent=scene,
            model='quad',
            color=color.azure,
            texture='lib/grass.png',
            highlight_color=color.red,
            position=position,
            **kwargs
        )
        self.tile_type = tile_type
        self.status = status
        self.contents = contents

        if self.tile_type == "sell":
            self.color = color.green

    def on_click(self):
        global selected_tile
        selected_tile = self
        print(f'Tile at {self.position} clicked!')
        self.color = color.red

    def update(self):
        global selected_tile

        if selected_tile != self:
            if self.tile_type == "sell":
                self.color = color.green
            else: self.color = color.azure

if os.path.exists("data/home.json"):
    with open("data/home.json", "r") as file:
        tiles_data = json.load(file)

    for tile_data in tiles_data:
        position = tile_data["position"]
        tile_type = tile_data["tile_type"]
        status = tile_data["status"]
        contents = tile_data["contents"]
        tile = Tile(position=position, tile_type=tile_type, status=status, contents=contents)
        tiles.append(tile)
else:

    for x in range(10):
        for y in range(9):
            tile = Tile(
                position=(x-6.75, y-4),
                tile_type="Empty",
                status="Idle",
                contents=None
            )
            tiles.append(tile)

def update():
    pass


app.run()
trim hemlockBOT
#

@stable tinsel

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.