Python Forum
[PyGame] Spawning platforms that don't touch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Spawning platforms that don't touch
#8
I personally don't care for his tutorials.
1. Uses way to many globals. You should get use to not using globals.
2. He always predefine colors. Pygame has over 400 builtin colors.

Example how you can handle spritesheet. This will let you grab images by name not rect.
import xml.etree.ElementTree as ET
from pygame.image import load as image_load
from pygame.transform import scale
from pygame import Rect

class JumpySpriteSheet:
    def __init__(self, filename, xmlfile):
        self.spritesheet = image_load(filename).convert_alpha()
        self.scale_sheet()
        self.image_dict = {}
        self.read_xml(xmlfile)

    def scale_sheet(self):
        size = self.spritesheet.get_size()
        size = size[0] // 2, size[1] // 2
        self.spritesheet = scale(self.spritesheet, size)

    def read_xml(self, xmlfile):
        tree = ET.parse(xmlfile)
        root = tree.getroot()

        for child in root:
            rect = Rect([int(child.get(attrib)) // 2 for attrib in ['x', 'y', 'width', 'height']])
            self.image_dict[child.get('name')[:-4]] = rect

    # reference
    def get_image(self, name):
        return self.spritesheet.subsurface(self.image_dict[name])
I get back to you with more later.
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: Spawning platforms that don't touch - by Windspar - Jan-23-2020, 07:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Timing the spawning enemies MichaelEssey 2 4,763 Aug-22-2020, 05:51 AM
Last Post: SheeppOSU
  spawning enemies in pygame Elberg 2 5,737 Mar-05-2020, 09:45 AM
Last Post: Windspar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020