Giter Site home page Giter Site logo

Comments (4)

oddbookworm avatar oddbookworm commented on June 15, 2024 1

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.

Damus666 avatar Damus666 commented on June 15, 2024 1

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.

oddbookworm avatar oddbookworm commented on June 15, 2024 1

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.

pinkteddybearfluff avatar pinkteddybearfluff commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.