I’m following a tutorial on youtube to create my own game for a school project using Clear Code’s Stardew Valley inspired game tutorial (https://www.youtube.com/watch?v=T4IX36sP_0c&t=7818s).
note: I have cut certain things out such as layering for the house, fences and some others because they are not necessary for my project.
My water graphics don’t seem to be animating despite everything seeming identical, aside from a couple scaling changes. I was wondering if it had something to do with a warning im getting from Pylance; “surf” is not accessed Pylance, and if not, I was hoping someone else had a solution. My animation for the player works perfectly fine so I’m unsure of why my water animation isn’t working now.
This is a snippet from my sprites.py file that I import into my level.py file!
class Water(Generic):
def __init__(self, pos, frames, groups):
# animation setup
self.frames = frames
self.frame_index = 0
# sprite setup
super().__init__(
pos = pos,
surf = self.frames[self.frame_index],
groups = groups,
z = LAYERS['water'])
def animate(self,dt):
self.frame_index += 5 * dt
if self.frame_index >= len(self.frames):
self.frame_index = 0
self.image = self.frames[int(self.frame_index)]
def update(self,dt):
self.animate(dt)
Here is my Level class in level.py
class Level:
def __init__(self):
# get the display surface
self.display_surface = pygame.display.get_surface()
# sprite groups
self.all_sprites = CameraGroup()
self.setup()
def setup(self):
tmx_data = load_pygame('../data/level1.tmx')
# water
water_frames = import_folder('../graphics/world/water')
for x, y, surf in tmx_data.get_layer_by_name('water').tiles():
Water((x * TILESIZE,y * TILESIZE), water_frames, self.all_sprites)
# background layer
Generic(
pos = (0,0),
surf = pygame.image.load('../graphics/world/ground.png').convert_alpha(),
groups = self.all_sprites,
z = LAYERS['ground'])
self.player = Player((480, 270), self.all_sprites) #(pos, group) from player class
def run(self, dt):
self.display_surface.fill('black')
self.all_sprites.custom_draw(self.player)
self.all_sprites.update(dt)
Thank you! <3
I have tried fiddling around with the format of the Water variables in level.py to make it look the same as Generic but that did absolutely nothing.
yori is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.