'pygame scrolling camera issue
I have x and y scrolling with the following code working fine, but it always starts from top left of map, and I wish it to start wherever the player object is positioned (player obj is called at particular tile position in map).
#update scroll
if self.char == 'hero':
if (self.rect.right > (screen_width//2 + 30) and self.direction_x == 1 and bg_scroll[0] < level_length - screen_width)\
or (self.rect.left < (screen_width//2 - 30) and self.direction_x == -1 and bg_scroll[0] > abs(dx)):
self.rect.x -= dx
scroll[0] = -int(dx)
if (self.rect.bottom > (screen_height//2 +40) and self.direction_y ==1 and bg_scroll[1] < level_height - screen_height) \
or (self.rect.top < (screen_height//2 - 40) and self.direction_y == -1 and bg_scroll[1] > abs(dy)):
self.rect.y -= dy
scroll[1] = -int(dy)
So I have tried for days to integrate a camera class and make my player obj the target but it has not worked and I have now created a variable that shows the full maps x/y position trying to use this minus player position to set the scroll speed but it does not work.
I feel to get the desired result I will to recode this with a proper camera class based around the object but I am struggling, Please help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
