Skip to main content
mi
Source Link
Pikalek
  • 13.4k
  • 5
  • 49
  • 54

yesYes, you can use a variable that can project to the positions of real world blocks on the screen:

WIDTH = 600
HEIGHT = 600

cam_pos = [0, 0]
smoothness = 0.5 # 0. -> smoother, 1 -> rigid

target_pos = player.rect.center

# in update
# update camera pos
'''dividing width and height by 2 so that it will center the target'''
cam_pos[0] += (target_pos[0] - cam_pos[0] - WIDTH/2) * smoothness
cam_pos[1] += (target_pos[1] - cam_pos[1] - HEIGHT/2) * smoothness

# player projection pos 
proj_x = player.rect.x - cam_pos[0]
proj_y = player.rect.y - cam_pos[1] 
screen.blit(player.image, (proj_x, proj_y))

applyApply this projection code to anything you want, tiles, entities, anything.

yes, you can use a variable that can project to the positions of real world blocks on the screen

WIDTH = 600
HEIGHT = 600

cam_pos = [0, 0]
smoothness = 0.5 # 0. -> smoother, 1 -> rigid

target_pos = player.rect.center

# in update
# update camera pos
'''dividing width and height by 2 so that it will center the target'''
cam_pos[0] += (target_pos[0] - cam_pos[0] - WIDTH/2) * smoothness
cam_pos[1] += (target_pos[1] - cam_pos[1] - HEIGHT/2) * smoothness

# player projection pos 
proj_x = player.rect.x - cam_pos[0]
proj_y = player.rect.y - cam_pos[1] 
screen.blit(player.image, (proj_x, proj_y))

apply this projection code to anything you want, tiles, entities, anything

Yes, you can use a variable that can project to the positions of real world blocks on the screen:

WIDTH = 600
HEIGHT = 600

cam_pos = [0, 0]
smoothness = 0.5 # 0. -> smoother, 1 -> rigid

target_pos = player.rect.center

# in update
# update camera pos
'''dividing width and height by 2 so that it will center the target'''
cam_pos[0] += (target_pos[0] - cam_pos[0] - WIDTH/2) * smoothness
cam_pos[1] += (target_pos[1] - cam_pos[1] - HEIGHT/2) * smoothness

# player projection pos 
proj_x = player.rect.x - cam_pos[0]
proj_y = player.rect.y - cam_pos[1] 
screen.blit(player.image, (proj_x, proj_y))

Apply this projection code to anything you want, tiles, entities, anything.

Source Link

yes, you can use a variable that can project to the positions of real world blocks on the screen

WIDTH = 600
HEIGHT = 600

cam_pos = [0, 0]
smoothness = 0.5 # 0. -> smoother, 1 -> rigid

target_pos = player.rect.center

# in update
# update camera pos
'''dividing width and height by 2 so that it will center the target'''
cam_pos[0] += (target_pos[0] - cam_pos[0] - WIDTH/2) * smoothness
cam_pos[1] += (target_pos[1] - cam_pos[1] - HEIGHT/2) * smoothness

# player projection pos 
proj_x = player.rect.x - cam_pos[0]
proj_y = player.rect.y - cam_pos[1] 
screen.blit(player.image, (proj_x, proj_y))

apply this projection code to anything you want, tiles, entities, anything