Hey,
I'm been working on a platformer.
I have a class for the character and inside it I have a list with all
the frames for every animation.
I`m having trouble animating the jumping sequence.
My main code looks something like this (I have stripped the code of
unnecessary functions, variables, class definitions, etc):
def key_handle(self):
if self.keyboard[key.UP] == True:
self.character.jump()
def draw_bkgrd(self):
self.bkgrd.blit(0,0)
def update(self):
self.clear()
self.draw_bkgrd()
def main_loop(self):
self.keyboard = key.KeyStateHandler()
self.music.play()
clock.set_fps_limit(15)
while not self.has_exit:
self.dispatch_events()
media.dispatch_events()
self.update()
self.character.draw()
self.push_handlers(self.keyboard)
self.key_handle()
clock.tick()
self.flip()
if __name__ == "__main__":
gWindow = GameWindow()
gWindow.main_loop()
My problem is this: if I push the UP key it executes the function, but
in that function I somehow have to make the character jump up and
animate.
I cannot simply do something like this in character class definition:
def jump(self,parent):
for i in range(5): #go up
self.current_image = self.frames['jump'][i]
self.y += 10
self.update()
self.parent.update()
for i in range(4,-1,-1): #fall back down
self.current_image = self.frames['jump'][i]
self.y -= 10
self.update()
self.parent.update()
(the self.update() simply blits the current image to the current x and
y)
This will ignore the framerate cap.
If I enter a clock.tick() inside the jumping function or the update it
will screw up the framerate. I have tried adding clock.tick() in the
for loops and while the framerate was ok, it stalled any music that
played until the animation was over.
Is there any way to create this jumping animation without the music
stalling? I know that when i push the UP key to jump I go into the
jumping loops and outside the mainloop and that's what makes the music
stall, but I have no other idea how to create the jumping animation.
I tried creating a variable that saves the current jump frame and
increments it without using a for loop but that requires me to keep
the UP key pressed until the animation is finished.
Any hint/idea would be helpful.
If anyone wants to see the full source code, just say so. I didn`t
post it yet because I didn`t think it is necessary.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---