Oyundaki Butonun Bir Parçası Haritanın Üstünde ve Gözüküyor Bir Kısmı Gözükmüyor

Merhabalar ben pygame ile oyun yapmaya çalışıyorum burada karşılaştığım sıkıntı ise ekrana çizdirdiğim butonun çerçevesinin görünmemesi TextButton sınıfının içinde butonumuza yazı ile daha rahat anlaşılabilmesi ve daha güzel gözükmesi için etrafına bir çerçeve çizdirdim. Ama sorun şu ki oyunu açtığımda butonun yazısı oyun haritasının üstünde görünürken çerçeve görünmüyor ama haritayı çizdirmediğim zaman hem butonun yazısı hem de çerçevesi görünüyor.

Not: Harita dediğim “main_world” olan çizim
Daha Önemli Not: Buton sınıfını internetten aldım kendim yapmadım. TextButon snıfını da kendim küçük oynamalar yaparak oluşturdum.

Kod:

import pygame, sys
import random
import ctypes
myappid = 'mycompany.myproduct.subproduct.version'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)

pygame.init()

# ekran ayarları
width = 900
heigh = 600
icon = pygame.image.load("icon.png")
main_win = pygame.display.set_mode((width,heigh))
pygame.display.set_caption("Oyun")
pygame.display.set_icon(icon)

# gömülü sınıflar
class TextButton():
	def __init__(self, x, y, text, fsize = 20, csize = 2, x_ayar = 3, y_ayar = 4, uzunluk_ayar = 6, yukseklik_ayar = 5):
		font = pygame.font.SysFont("calibri", fsize)		
		self.text = font.render(text, True, (255,255,255))
		self.rect = self.text.get_rect()
		self.rect_width = self.text.get_width()
		self.rect_heigh = self.text.get_height()
		self.rect.topleft = (x, y)
		self.cerceve = pygame.draw.rect(main_win, (255,255,255), (x - x_ayar, y- y_ayar, self.rect_width + uzunluk_ayar, self.rect_heigh + yukseklik_ayar), csize)
		self.clicked = False

	def draw(self, surface):
		action = False
		#get mouse position
		pos = pygame.mouse.get_pos()

		#check mouseover and clicked conditions
		if self.rect.collidepoint(pos):
			if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
				self.clicked = True
				action = True

		if pygame.mouse.get_pressed()[0] == 0:
			self.clicked = False

		#draw button on screen
		surface.blit(self.text, (self.rect.x, self.rect.y))

		return action
class ImageButton():
	def __init__(self, x, y, image, scale):
		width = image.get_width()
		height = image.get_height()
		self.image = pygame.transform.scale(image, (int(width * scale), int(height * scale)))
		self.rect = self.image.get_rect()
		self.rect.topleft = (x, y)
		self.clicked = False

	def draw(self, surface):
		action = False
		#get mouse position
		pos = pygame.mouse.get_pos()

		#check mouseover and clicked conditions
		if self.rect.collidepoint(pos):
			if pygame.mouse.get_pressed()[0] == 1 and self.clicked == False:
				self.clicked = True
				action = True

		if pygame.mouse.get_pressed()[0] == 0:
			self.clicked = False

		#draw button on screen
		surface.blit(self.image, (self.rect.x, self.rect.y))

		return action

# gömülü fonksiyonlar
def yaz(text, x, y, renk, size = 15, font = "calibri"):
	font = pygame.font.SysFont(font, size)
	yazi = font.render(text, True, renk)
	main_win.blit(yazi, (x, y))

# global değişkenler 
clock = pygame.time.Clock()

# resimler
#dugme = pygame.image.load("assets/cikis_dugme.png")

bg = pygame.image.load("main_world.png")
bg = pygame.transform.scale(bg, (width, heigh))

# düğmeler
#saldir_tus = ImageButton(20,20,dugme,1)
yazi_tus = TextButton(20,350,"Saldır", fsize= 20, csize= 3)

# döngü 
loop = True
while loop:
    
    main_win.blit(bg, (0,0))
    
    # tuş kontrol
    #if saldir_tus.draw(main_win):
    #    print("oldu")
    if yazi_tus.draw(main_win):
    	print("yine oldu")
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = False
        if event.type == pygame.KEYDOWN:
            pass	

    pygame.display.update()	
    clock.tick(60)
pygame.quit()
sys.exit()

Resimler:

Yaziyi draw'da ama cerceveyi __init__'te ciziyorsun.

1 Beğeni

Teşekkürler nasıl bunu kaçırdım bilmiyorum.