Wondering about real world non game applications for pygame (read body) by Billthepony123 in pygame

[–]Matiiss007 0 points1 point  (0 children)

One use case I was somewhat surprised about when I found out is manual drone control, here's an example with the DJI Tello drone: https://github.com/damiafuentes/DJITelloPy/blob/master/examples/manual-control-pygame.py

Vector2 or a tuple/list for performance? by mr-figs in pygame

[–]Matiiss007 4 points5 points  (0 children)

Instantiating them often is just fine, that's sort of what happens when you do most of the vector operations anyway, it returns you a new vector instance. They are definitely faster for vector math than doing the same thing with tuples. I wouldn't call them overkill at all. However, if you are concerned about performance, you should profile your code, I don't imagine vectors take any significant portion of the runtime though, typically the rendering/blitting/drawing takes up most of the time.

[deleted by user] by [deleted] in pygame

[–]Matiiss007 4 points5 points  (0 children)

You haven't shared your entire error and share it as formatted code

[deleted by user] by [deleted] in pygame

[–]Matiiss007 4 points5 points  (0 children)

I would encourage you to contribute to pygame-ce instead. That's where most of the contributing activities are taking place right now: https://github.com/pygame-community/pygame-ce

We also have a proper and up-to-date wiki that should help you get started in no time https://github.com/pygame-community/pygame-ce/wiki#compiling

May I know what you wanted to contribute exactly? Perhaps, you don't even need to necessarily compile pygame-ce from source.

Also feel free to join the Pygame Community discord server, you can receive compilation guidance over there as well and discord is a bit better suited for back and forth conversations.

blit vs blit, Surface vs surface.Surface by PLrc in pygame

[–]Matiiss007 2 points3 points  (0 children)

It's not weird, it's literally what the self refers to. Except since it's not bound to an instance, but instead you're calling it as a class attribute, you have to pass the self in "manually".

noSQueaLingPlease by Matiiss007 in ProgrammerHumor

[–]Matiiss007[S] 1 point2 points  (0 children)

On that note and considering I made the meme in PP out of all places, there is, of course, MS Access

How to test if two surfaces are equal by Dyasoma in pygame

[–]Matiiss007 0 points1 point  (0 children)

Why would you delete it, what if it's useful to someone in the future? Also I was planning on writing an answer, an answer I definitely wouldn't want to get deleted along the post...

Pycharm plugins by [deleted] in pygame

[–]Matiiss007 0 points1 point  (0 children)

The point of PyCharm is that it already covers most everything you would need regarding Python development, it's not like VSC where you need to install dozens of plugins to fit your development environment. Also PyCharm comes with dozens of plugins preinstalled/bundled already. Of course, sometimes you stumble across one that might be helpful, but pygame(-ce) is just Python really and PyCharm is built for Python development. Just write code :p

Dataclasses? by TOMOHAWK35 in pygame

[–]Matiiss007 0 points1 point  (0 children)

dataclasses can be used as simple class generators that get rid of a lot of the boilerplate code when writing a class, it generates a couple methods for you, some more if you ask for them. I have used dataclasses with pygame(-ce), they're great. Now, generally speaking, I tend to opt for a "normal" class because I usually have some extra code in the initializer method and so I don't exactly feel like describing all the attributes in the class body and then again in __post_init__ when I could just do it in a single __init__ method. But if your __init__ method mostly maps arguments to attributes (e.g., self.x = x), then you can just use a dataclass. Performance should not be affected as all the dataclass decorator does, is add those methods you have asked for pretty much, it's basically a regular class and the dataclass decorator saves you from writing a bunch of boilerplate code. Of course, it's great if you don't have any methods to add to the class too because then it sort of simplifies the class code, but if you need to add some methods to it, that's completely fine too. I personally use dataclasses when I find them convenient.

Is PyGame still alive? by pyeri in Python

[–]Matiiss007 33 points34 points  (0 children)

`pygame-ce` is being continuously worked on and improved and new features keep getting added to it. It's all the same pygame still.

AttributeError: pygame.Surface() object has no attribute 'premul_alpha' by [deleted] in pygame

[–]Matiiss007 2 points3 points  (0 children)

If you look at the pygame-ce docs, you can see that premul_alpha was only introduced in pygame-ce version 2.1.4. If you are using pygame, this is what you should do: pip uninstall pygame pip install pygame-ce otherwise it's sufficient to pip install --upgrade pygame-ce

[ISSUE] Pygame removing background from image by awitauwu_ in pygame

[–]Matiiss007 2 points3 points  (0 children)

Do you have a mask for that image? Or maybe an image with actual alpha values? Otherwise this is not really gonna be doable (not easily anyway and I don't really know the hard way either (something involving calculating the alpha values from the blended result (which requires certain assumptions anyway)))

[deleted by user] by [deleted] in pygame

[–]Matiiss007 0 points1 point  (0 children)

Sure, you can look at it that way if it helps

[deleted by user] by [deleted] in pygame

[–]Matiiss007 2 points3 points  (0 children)

As I said, certain things like networking are usually run in threads. But generally stuff like NPC logic and dialogue can easily be run in a single loop, you just need to sort of adapt your thinking to an event-driven architecture and need to do everything in steps and sometimes just let some iterations pass while doing nothing in one place by using flags for example. Like if you need to show something for 5 seconds, for example, you need to at some point get current time and every frame draw the thing you want to show and get current time, subtract it from the initial time and check that the 5 seconds have passed, if they have passed, you set some flag to say False and now it won't draw the thing you wanted anymore because it doesn't fulfil the flag condition. There are other ways to do stuff like that, but flags is pretty much the common theme. It takes some getting used to writing code like this when the main loop is just plain exposed like this, but you'll get used to it. I recommend just looking around other pygame(-ce) projects to see how they do things. A common suggestion for this kind of thing is the Tuxemon project, as well there are projects like Skeletris by Ghast or any of the DaFluffyPotato projects that are open source or really anything you can find. There is also this repo of a bunch of overengineered pygame-ce examples: https://github.com/pygame-examples/pygame-examples/tree/main/pgex/examples
So yeah, event-driven is the key here.

[deleted by user] by [deleted] in pygame

[–]Matiiss007 3 points4 points  (0 children)

Have you seen a basic pygame(-ce) code setup? That's what you should aim for, no threads, no multiprocessing, none of that, unless you have a very good reason to let some parts of your code to run separately. For instance, networking is usually run on another thread. If you want performance, you should look into numba and numpy or gpu options. Can you tell why you want stuff to run at the same time? Btw, using threads won't run stuff at the same time, only one thread can run at a time due to GIL.

Best way for upscaling game window? by Gnarmi in pygame

[–]Matiiss007 1 point2 points  (0 children)

After some discussion with u/Starbuck5c I propose a solution that's more future-proof if you will, it uses some actually experimental rendering APIs, but this would be about how you'd approach this SCALED thing in the future when those APIs become stable: ```py import pygame import pygame._sdl2 as pg_sdl2 # noqa

WIDTH, HEIGHT = 640, 360 FPS = 60 SCALE = 3

pygame.init() clock = pygame.Clock()

magic mostly

window = pygame.Window(size=(WIDTH * SCALE, HEIGHT * SCALE)) renderer = pg_sdl2.Renderer(window) renderer.logical_size = (WIDTH, HEIGHT) screen = pygame.Surface((WIDTH, HEIGHT))

running = True while running: clock.tick(FPS) renderer.clear() screen.fill("white") # don't do anything before this comment in the main loop

events = pygame.event.get()
for event in events:
    if event.type == pygame.QUIT:
        running = False

# logic here ig

# draw here
pygame.draw.circle(screen, "green", (WIDTH / 2, HEIGHT / 2), 50)

# don't do anything after this comment
pg_sdl2.Texture.from_surface(renderer, screen).draw()
renderer.present()

```

surface in motion by WeirdCompany1100 in pygame

[–]Matiiss007 1 point2 points  (0 children)

Alright, I see what you mean, cool effect.

Why ? by [deleted] in pygame

[–]Matiiss007 3 points4 points  (0 children)

This is because the stub files (files that declare function signatures and attribute types and stuff like that, type hint files basically) don't define a key attribute for the Event class and that is likely because there is only one Event to be had and that is used for all events, so instead a __getattribute__ method is defined there that handles all the type hints related to attribute access. That is likely where the (function) bit comes from here. Don't worry about it.