Skip to main content
Share Your Experience: Take the 2024 Developer Survey
8 votes

How can I make the player "look" to the mouse direction? (Pygame / 2D)

First you need to calculate the vector pointing from your player to the current mouse position. This can be done by subtracting the player's position with the mouse's position: ...
Ted Klein Bergman's user avatar
6 votes
Accepted

How to get rid of the white border/background on my png image?

Use a file format that supports alpha (png), an editor that can save it with a transparent background (gimp2, photoshop, basically not paint) and make sure you load the sprite correctly
Bálint's user avatar
  • 14.9k
4 votes

Doing an SNES Mode 7 (affine transform) effect in pygame

Here is the code to make it. I is the same code of the tutorial that I made on my blog. Check there to learn the Mode 7 method and the RayCasting. Basically, the pseudo code is it: ...
Vinícius Biavatti's user avatar
4 votes

Too slow for cycle in Pygame

Your problem here is that this does not work for CPU, it should be done using GPU, probably you can access it in pygame. It's the work of pixel shader and it works on very low level, with thousands of ...
Candid Moon _Max_'s user avatar
3 votes
Accepted

2d MMO world generation?

I couldn't tell from your question if your world is top down or side on. But I'm going to assume top down for my answer. If you just want the blocks to be totally random, all you'd need to is go ...
Grady's user avatar
  • 435
3 votes
Accepted

Implementing Story and Quests in RPG

As far as I see it the Shop class (for example) needs dependencies on at least two classes: The current status of the player-character (things like available money,...
Philipp's user avatar
  • 120k
3 votes

Rotating hitboxes in PyGame?

Building on Tyyppi_77's answer above, there are a few approaches you can take: 1) Resizing the hit box (as he suggests) - although you can do it much much easier just by using image.get_rect(), which ...
Chris's user avatar
  • 191
3 votes

PYGAME: When I release two directional keys together the player keep moving

In pygame (and many other frameworks like it), events are received in an event queue. Multiple events can arrive per frame, for example when you press or release two buttons together. You need to ...
congusbongus's user avatar
  • 14.8k
3 votes

Locking the frame rate in pygame?

clock.tick() only sets the loops at intervals of milliseconds, so at 60 fps, it will make each game loop at 16 milliseconds, not 16.6666 (which is what you need) ...
William Hou's user avatar
3 votes

How to make an object move outside the map and appear on the other side with a tilemap?

Your set_target() method currently chooses the next tile to move your player. You will need to know the bounds of your tilemap to move the player to the other side when reaching a wall. A simple way ...
Simon N.'s user avatar
  • 186
3 votes
Accepted

Performance drawing in Pygame

I resolved the issue I was facing severe fps drops using my background image and blocks. Though I changed it so when I loaded them into my program, I used .convert() at the end. The .convert() made a ...
Kyle's user avatar
  • 69
3 votes
Accepted

What is the difference between Pygames, Pyglet and Kivy and how each helps python game development?

The difference between the three frameworks/engines is the abstraction level. Pyglet is low level compared to the other two and is based on SDL, a popular C++ multimedia library. You'll have to use ...
Bálint's user avatar
  • 14.9k
3 votes

Separate objects for hitbox and sprite?

Instead of making your player object inherit from the sprite class you could use member variables for the sprite and rect. Your player class can then stand alone, and have separate sprite and rect ...
Jay's user avatar
  • 810
3 votes
Accepted

How do I port a game which uses print-output to pygame font rendering with the least amount of work?

This sounds like a pretty classic abstraction problem, general to all programming and not just games. I'll provide some explanation in terms of a text game though to suit your question. Absolutely ...
Sean Middleditch's user avatar
3 votes
Accepted

Ensure that random enemies don't spawn just near the player

The simplest system I can think of consists in testing the position of the new enemy before your screen.blit(), like so: ...
Sisyphe's user avatar
  • 66
3 votes

How to properly set up a lives system for a side-scroller in pygame

The player loses many lives because you don't tell your game to ignore collisions after the first frame there is a collision. Since there is a collision detected each frame, another life will be ...
Vaillancourt's user avatar
  • 16.3k
3 votes
Accepted

Creating a nav mesh

TLDR: Which option to use depends on the need. Grid-based maps use navmesh will have additional workload, but the effect is better in most cases. Navmesh is essentially an optimization of a grid-based ...
Mangata's user avatar
  • 2,571
2 votes

RPG movement holding down button

I believe that this is what you were looking for: ...
Ethan McRae's user avatar
2 votes
Accepted

How to figure out which tiles are within view, and where to draw them in the grid?

To make the camera move when the player gets near the edge of the screen, you're going to need to set up a collision for the player to hit. In the image, as the player moves closer to the displays ...
Flutterguy135's user avatar
2 votes

How to program destructibles?

A rational approach might be to simplify your problem. This is a game, so most of the time there is no need for 100% accurate physics. Instead of tracking every single component that makes your ship, ...
rlam12's user avatar
  • 380
2 votes
Accepted

How to integrate Tiled maps and collision detection with pygame?

Since no other solution to this question has been posted - and I now know a solution - I figured I would answer my own question so it may be useful for others. Consider the Tiled map that looks like ...
James's user avatar
  • 183
2 votes

How to rotate an image in pygame without losing quality or increasing size or moving position

Maintaining quality When you're rotating the image using pygame.transform.rotate(), pygame creates a new Surface with your rotated image on. By doing this your ...
Ted Klein Bergman's user avatar
2 votes

Pygame wall collision is acting very odd

You might need to look into axis separation. When it comes to collision detection in 2d with rects, you need to split up your movement and collision detection into separate x- and y-axis. In other ...
mbzdkc's user avatar
  • 91
2 votes
Accepted

How should I make a jump-timing game's character static on screen?

You're overthinking it. For the dinosaur game, you need 2 sprites (don't worry about the pterodactyl or different sized cactuses yet): Dino The dino doesn't move left/right - he stays in the same ...
Chris's user avatar
  • 191
2 votes

How do I set the truck to run on the road, recognizing the black edge as the road?

Note: I'd suggest to create your own, instead of ripping these off the original game. That will give you more control, and will avoid any copyright issues. how to recognize the black edge as the road?...
Theraot's user avatar
  • 27.1k
2 votes
Accepted

Implementing Jump in pygame

It's actually pretty simple! When you jump, you have upwards velocity that is greater than the force of gravity. As time progresses this upwards velocity starts to decrease because of gravity! After ...
J22o's user avatar
  • 482

Only top scored, non community-wiki answers of a minimum length are eligible