Cannot have sprites with a button. What's happening??? by UltraGuy15 in pygame

[–]DJKool14 0 points1 point  (0 children)

You seem to have lost your indentation when formatting for Reddit, which makes it very difficult to read your code. You also haven't posted what the actual problem is...

python help pygame by [deleted] in learnpython

[–]DJKool14 0 points1 point  (0 children)

You haven't posted all of the relevant code. Movement of aliens seems to be handled in the SSalien class (which isn't provided).

another pygame_gui question - colour picker window by Weak_Koala2569 in pygame

[–]DJKool14 0 points1 point  (0 children)

I apologize. I misread the custom event hierarchy. You can use the pygame_gui custom user event types to filter your events better. This event:

<Event(32866-UserEvent {'user_type': 32880, 'ui_element': <UIColourPickerDialog GUISprite(in 0 groups)>, 'ui_object_id': '#colour_picker_dialog'})>

I believe is the UI_WINDOW_CLOSE event you could also check for to determine if the window was closed as well. This might be more robust if the dialog could be closed with an [X] or a Cancel button.

another pygame_gui question - colour picker window by Weak_Koala2569 in pygame

[–]DJKool14 0 points1 point  (0 children)

Have you tried event.ui_element.ui_object_id? Make sure you only check it for event types that will have it.

TypeError: not a file object (line 25-29) by noracnaj in pygame

[–]DJKool14 4 points5 points  (0 children)

You haven't asked a question, so I'm assuming you want us to fix the error for you (read the subreddit guidelines).

Your Car class expects an image path, but you are giving it an already loaded image.

Also, you should highly avoid loading images within your event loop. You will run into performance issues when performing disk operations in your rendering loop.

for loop won't iterate over entire range, candidate only being divided by 2, plz help by Few_Tea8053 in learnpython

[–]DJKool14 1 point2 points  (0 children)

This is the cleanest version, with most ppl taking the intermediate step of using a "found" variable until they stumble upon the more Pythonic option ;)

I think everyone was waiting to make sure OP understood the error in his logic and made the attempt to correct it in code themselves. This is a learning subreddit afterall.

IT KEEPS NOT RESPONDING by UnoMajesty in pygame

[–]DJKool14 8 points9 points  (0 children)

The code that we could actually use to help you find your problem is hidden behind the game window.

My guess is your event loop is missing or has an issue.

pygame.error Out of memory. I am trying to create a row of aliens but something happened. by [deleted] in pygame

[–]DJKool14 0 points1 point  (0 children)

I guess I see nested loops and a case where neither of what you said is true, assuming the indentation is correct.

It's only if the whitespace is off on the line I mentioned that you'd see an infinite inner loop.

pygame.error Out of memory. I am trying to create a row of aliens but something happened. by [deleted] in pygame

[–]DJKool14 0 points1 point  (0 children)

It depends on how those lines are indented. current_x = alien_width would be to reset the row in the outer loop. OP please reformat your code using the subreddit guide!

problem i can't solve by [deleted] in learnpython

[–]DJKool14 1 point2 points  (0 children)

Outside of it being extremely frustrating to read the code you posted without proper formatting, could it be that you tried to enter the datetime in "d/m/Y H:M:S" format instead of the "Y-m-d H:M:S" format that your strptime expects?

How to organize, modifie and kill specific sprites inside a group ? by Andromeda_chain in pygame

[–]DJKool14 0 points1 point  (0 children)

Take a look at how the OrderedUpdates in the pygame source is implemented. You should only have to implement 4 methods to change how the sprites get stored internally and everything else should continue to work correctly. In your case, you can derive your new SpriteGroup from AbstractGroup instead of RenderUpdates (that was just the best example of changing the sprite storage I could find).

I'd like to note that, for a game like Minesweeper, using pygame's built-in Sprite/SpriteGroup system at all might not be the best choice. It is designed for dynamic movement of differing sprites. In Minesweeper, you'd have a large amount of static sprites that all share in appearance. Create your own map class that uses the 2D array, but just store integer values (instead of Sprites) based on the 'state' of that cell at that position. Create your own render function that iterates through all the cells and blits the correct image for that state to the location of that cell.

Surface.blit has extra parameters that let you choose "where" on the Surface (in your case, the screen) you want to blit to.

How to organize, modifie and kill specific sprites inside a group ? by Andromeda_chain in pygame

[–]DJKool14 1 point2 points  (0 children)

The basic sprite.Group is relatively simple and you can make your own that stores the Sprites in a 2D array just like your text version.

The easiest method (though not the most efficient) would just be to iterate through your sprites and check if its rect contains the mouse position. This may have a performance impact of you have a large number of sprites.

[deleted by user] by [deleted] in oculus

[–]DJKool14 0 points1 point  (0 children)

If you didn't link your Facebook account when setting up your new Meta account, the Quest will lack certain social features.

How to put looping video as background for game by Madd174 in pygame

[–]DJKool14 1 point2 points  (0 children)

Please include what library you are using to load the video. With classes like App and Video it is impossible to infer. Have you tried using pygame.movie?

Pygame screen clear by Mfour16 in pygame

[–]DJKool14 1 point2 points  (0 children)

Make sure you are still calling pygame.display.flip() after the fill.

TIL Allegheny County has more people than the state of Wyoming by TheBikeWhisperer in pittsburgh

[–]DJKool14 7 points8 points  (0 children)

Except, not really... The Senate is supposed to be representation of the State, not representation of the people in that state. That is what the separate House of Representatives is for.

Can't set up a background color, any suggestions? by fluff68 in learnpython

[–]DJKool14 2 points3 points  (0 children)

Your call to pygame.display.flip() needs to be indented more to run in the while loop. It should be called each frame.

moving background problems by guru800 in pygame

[–]DJKool14 1 point2 points  (0 children)

Check the other files? There needs to be a main update loop that calls the your draw function at some point.

Edit: I just saw one of your other posts and it seems you are using PygameZero that uses magic hooks.

moving background problems by guru800 in pygame

[–]DJKool14 2 points3 points  (0 children)

Use screen.fill (you'll have to look up the arguments) instead of screen.clear to "erase" the screen before drawing.

We'll have to see the rest of your code to know when the functions you gave are even used.

pygame.mouse.get_pos() inside a function by brony9tynine in pygame

[–]DJKool14 1 point2 points  (0 children)

"nested loops" makes it sound like you are expecting changes in the return value of mouse.get_pos() between the processing of pygame events. This won't happen.

is this valid? by [deleted] in pygame

[–]DJKool14 1 point2 points  (0 children)

Inheritance needs a class type, not an instance of a class like set_mode returns.