Comments (4)
I suspect this is an issue with the fact that normal rects truncate to integers. At higher fps, dt is so small that 300*dt is probably less than 1, making it essentially adding 0 when you add it to an integer. Try using an frect instead or using a vector for your position, and update the rect from that
from pygame-ce.
It's not an issue with pygame, as oddbookworm said it's the wrong rect usage. Either a FRect or a Vector2 would work. replacing get_rect with get_frect completely fixes the issue
from pygame-ce.
it doesn't work with the combination of only get_rect and pygame.math.Vector2()
No, it works perfectly fine if you use them correctly. Here's your code modified to use a vector for positioning. Note that you should also move the pygame.display.flip()
call to after you do your drawing
import pygame
pygame.init()
running = True
clock = pygame.time.Clock()
player_surf = pygame.Surface((32,32))
player_surf.fill("red")
player_pos = pygame.Vector2(640, 360)
player_rect = player_surf.get_rect(center = player_pos)
screen = pygame.display.set_mode((1280,720))
FPS = 500
while running:
dt = clock.tick(FPS)/1000
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
player_pos.y -= 300*dt
if keys[pygame.K_DOWN]:
player_pos.y += 300*dt
if keys[pygame.K_LEFT]:
player_pos.x -= 300*dt
if keys[pygame.K_RIGHT]:
player_pos.x += 300*dt
player_rect.center = player_pos
#pygame.display.flip()
screen.fill(pygame.Color(48,48,48))
screen.blit(player_surf, player_rect)
pygame.display.flip()
pygame.quit()
from pygame-ce.
As oddbookworm and Damus666 said , it worked perfectly fine by using frect but it doesn't work with the combination of only get_rect and pygame.math.Vector2() but as get_frect is new I will be using that anyways, so the issue is solved.
Thank You
from pygame-ce.
Related Issues (20)
- pygame.mouse.set_pos() is not working under wayland HOT 3
- Gaussian-blurred alpha doesn't appear to blit correctly onto another semi-transparent surface HOT 8
- `pygame.Surface.fblits` slower in 2.5.0.dev2 vs 2.4.1 HOT 13
- Remove xwayland warning
- **TRACKER** Tracking changes that must be done when we start migrating to SDL3 in earnest HOT 1
- Port `TTF_SetFontHinting`
- New test fail in `set_system_cursor` when integer value passed is out of range
- pygame.mouse.get_just_pressed()? HOT 1
- Unhelpful error message in pygame.transform.gaussian_blur() with zero-dimensioned surfaces HOT 2
- Working with audio generates error (WSL2 - Windows11) HOT 2
- Portmidi broke cython HOT 1
- Add additional instruction for users encountering "No Module error" while Generating the Document
- Grammar: Missing comma in main Readme? HOT 1
- Local test fails: When compiling from Source on Raspberry Pi HOT 1
- Enhance window with OpenGL with viewport and documentation
- Move tutorials out of main repo into their own repository HOT 9
- DOC: Add CONTRIBUTION.md and Contribution section to README? HOT 11
- `python -m docs` doesn't open development docs
- `import pygame.debug` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygame-ce.