I just watched a tutorial with more complicated code using a sprite sheet so you split it into evenly sized sections and then load in the column and row etc then I find you can just use a gif as I was going to do originally. Oh well at least I know for the next project, great vid!
Great tutorial. Focus on one thing only and done good. PS: You could get the direction and last thing is update frame, in this way you end up where you keyup. last_Direction = 0 while True: if clock() > nextFrame: # We only animate our character every 80ms. frame = (frame+1)%8 # There are 8 frames of animation in each direction nextFrame += 80 # so the modulus 8 allows it to loop if keyPressed("num6"): last_Direction = 0*8+frame elif keyPressed("num2"): last_Direction = 1*8+frame elif keyPressed("num4"): last_Direction = 2*8+frame elif keyPressed("num8"): last_Direction = 3*8+frame changeSpriteImage(testSprite, last_Direction)
You should use a graphics editing program to resize and prepare images. I use GIMP, which is free. You can resize Sprites using transformSprite, but I would avoid this if you can as it's less efficient.
@@PagetTeachesHow would i change the image size? I tried making the splices smaller inside a big transparent image but it is still appearing 'inlarged' in my game? I use Adobe photoshop
Are you saying you have created a smaller version of the image in Photoshop, but the game is still displaying them large? Are you sure you're loading the smaller sprite sheet, instead of the original large one?
If I'm looking for better performance, what is the preferred way of doing sprite animations: a) by importing multiple graphic files, each with a single animation frame, or b) as a single file that contains all the sprite animations?
Well, I didn't draw them! I used the Link sprite sheet (which you can find from various sites). They came in the form of a massive sheet of all the sprites from the game. To make my smaller sprite sheet I just copied each frame that i wanted and arranged them into a long image. (I used the free image editor GIMP for this, but any decent image editor would probably do) So long as they are lined up vertically and evenly spaced out horizontally, pygame_functions will split them up appropriately. If you have trouble making the sheet, and if you find it easier to just have lots of individual frames in separate images, you can still animate them. Just add them to the sprite using addSpriteImage for each one.
I am just curious about the format of sprite sheets in general (I am very new to this). The current sprite sheet I am looking at have multiple movement position in the same PNG file. I've also found that finding a Gif of your sprite along with the sheet isn't very common from what I can tell. How are you compensating with these different formats? Is there a way to convert PNG sheet to gif? Can I just feed it the PNG sheet? How do I break up the sheet in to individual smaller frames?
The gif is just a converted PNG. It's not an animated file, so a PNG would work just as well. I got a copy of a sprite sheet, put it into something like GIMP and cut out all the frames I wanted to use. I created a canvas that was 32 times the max width of a frame (I settled on 100 as it doesn't have to be exact) and then spaced each frame at 100px intervals. I seem to remember that when I ran the animation, I had to go back in and shift a few frames by a pixel or two to make it look natural (he bobs up and down when running). There are almost certainly tools to make a sprite sheet more efficiently. Pygame could also do with an adjustment to allow you to use a 2D Sheet
By default, the showSprite command updates the whole screen, which can be a bit flickery. To stop this, turn off auto-updating. This video shows you how: th-cam.com/video/SA0F6Huj9dg/w-d-xo.html
Imported your pygame_functions and have everything. Created a small gif with one 2 frames. But when I try to get the GIF into the project, then it tells me "Pygame.error: No Video mode has been set".. What did I miss?
Yeah, I did. I’ll look into it a bit more. Mainly working with PyQt5 and matplotlib and other libraries. Just started pygame because I can see that you can both make games and actually apply it to some drone programming. Perhaps I scaled or did something wrong with my GIF as I just did some pixel animation in Aseprite..
Hello, whenever I try to implement this in, it comes back with the error: 'NameError: name 'makeSprite' is not defined'. Am I forgetting something here?
@@PagetTeaches thanks loveyour vids! But also one thing, I am having difficulty making the sprite jump! It sounds simple but please can you tell me the code because I really need it and dont know how to find y coordinate on pygame_functions! You can tell that I am new so please can you help me? one last thing is that i am making a 2D game so there is only going left and right (not up and dow). that is why i need your help! Please help.
Good point. I know this would be useful. I suspect it would need some tweaks to the events handling of the current version, to allow functions to be attached to buttons. I'll look into it.
The exact number isn't important. But a delay of 80ms means you get 12.5 frames of animation per second, which is roughly what is used in films like classic Disney or Stop Motion animation.
Rengo L. In the bottom of pycharm there is a button called terminal, click it. When in the terminal type: Pip install pygame Then press enter. If that doesn’t work then idk how to do it.
Robobros 21 thank you ! I have done this before starting my project. Idk what’s going on, maybe this function has been integrated in another like : from pygame import locals * ?
I love you, just speend 2 hours looking for an way to make the frames work and you show in 5 minutes, thank you.
Yeah!!!
This is the most helpful video I've ever come across on TH-cam. Thank you so much.
I've never used python and i found this really easy to understand because of you
thank you man
this is a lifesaver for my game i spent 3 hours trying to make a time system thank you very much!
I just watched a tutorial with more complicated code using a sprite sheet so you split it into evenly sized sections and then load in the column and row etc then I find you can just use a gif as I was going to do originally. Oh well at least I know for the next project, great vid!
Many thanks! Looking forward to the scrolling background!
Man... This method is amazing, congratulations
Great tutorial. Focus on one thing only and done good.
PS: You could get the direction and last thing is update frame, in this way you end up where you keyup.
last_Direction = 0
while True:
if clock() > nextFrame: # We only animate our character every 80ms.
frame = (frame+1)%8 # There are 8 frames of animation in each direction
nextFrame += 80 # so the modulus 8 allows it to loop
if keyPressed("num6"):
last_Direction = 0*8+frame
elif keyPressed("num2"):
last_Direction = 1*8+frame
elif keyPressed("num4"):
last_Direction = 2*8+frame
elif keyPressed("num8"):
last_Direction = 3*8+frame
changeSpriteImage(testSprite, last_Direction)
Thanks, dude. Good suggestion!
if anyone is stuck on why something doesn't happen check if you name you're file pygame.py maybe thats whats not working
Nice video, how should i do if my sprite sheet is not a single line(I mean an array for example)?
How can I do this if the sprite sheet is multiple rows?
How do i reduce the size of my sprite? Its very large for the world i have made
You should use a graphics editing program to resize and prepare images. I use GIMP, which is free.
You can resize Sprites using transformSprite, but I would avoid this if you can as it's less efficient.
@@PagetTeachesHow would i change the image size? I tried making the splices smaller inside a big transparent image but it is still appearing 'inlarged' in my game? I use Adobe photoshop
Are you saying you have created a smaller version of the image in Photoshop, but the game is still displaying them large?
Are you sure you're loading the smaller sprite sheet, instead of the original large one?
@@PagetTeaches yes, i chose the right image also. is there a command that can scale sprites?
@@theroby27 yes, it's transformSprite. github.com/StevePaget/Pygame_Functions/wiki/transformSprite
If I'm looking for better performance, what is the preferred way of doing sprite animations: a) by importing multiple graphic files, each with a single animation frame, or b) as a single file that contains all the sprite animations?
Great video! Could you possibly explain how you made the spritesheet/images for the spritesheet?
Well, I didn't draw them! I used the Link sprite sheet (which you can find from various sites). They came in the form of a massive sheet of all the sprites from the game. To make my smaller sprite sheet I just copied each frame that i wanted and arranged them into a long image. (I used the free image editor GIMP for this, but any decent image editor would probably do)
So long as they are lined up vertically and evenly spaced out horizontally, pygame_functions will split them up appropriately.
If you have trouble making the sheet, and if you find it easier to just have lots of individual frames in separate images, you can still animate them. Just add them to the sprite using addSpriteImage for each one.
@@PagetTeaches Brilliant answer, thank you!
I am just curious about the format of sprite sheets in general (I am very new to this). The current sprite sheet I am looking at have multiple movement position in the same PNG file. I've also found that finding a Gif of your sprite along with the sheet isn't very common from what I can tell. How are you compensating with these different formats? Is there a way to convert PNG sheet to gif? Can I just feed it the PNG sheet? How do I break up the sheet in to individual smaller frames?
The gif is just a converted PNG. It's not an animated file, so a PNG would work just as well. I got a copy of a sprite sheet, put it into something like GIMP and cut out all the frames I wanted to use. I created a canvas that was 32 times the max width of a frame (I settled on 100 as it doesn't have to be exact) and then spaced each frame at 100px intervals. I seem to remember that when I ran the animation, I had to go back in and shift a few frames by a pixel or two to make it look natural (he bobs up and down when running).
There are almost certainly tools to make a sprite sheet more efficiently. Pygame could also do with an adjustment to allow you to use a 2D Sheet
just subscribed great video my g
for me the character won't move, any clue to why this is?
Can someone help me please? My code gives me no errors, the game runs, but my sprite doesnt show, even tought I used the showSprite method.
If you post your code on the issues page of the github, I'll take a look
@@PagetTeaches wow, I didnt think you would still answer comments here! hahaha thank you, I will post it there!
@@lucasesposito9041 ok, have a look. I've posted a possible fix
Hey my images are flickering when I type in "showSprite" any idea why?
By default, the showSprite command updates the whole screen, which can be a bit flickery. To stop this, turn off auto-updating. This video shows you how: th-cam.com/video/SA0F6Huj9dg/w-d-xo.html
@@PagetTeaches Thank you so much for the quick reply, that worked out perfectly for me!
Could you write if the frame is greater than 8 reset it to 0. I hope that makes sense?
Two ways:
If frame > 8:
frame=0
Or
Frame = frame % 8
Imported your pygame_functions and have everything. Created a small gif with one 2 frames. But when I try to get the GIF into the project, then it tells me "Pygame.error: No Video mode has been set".. What did I miss?
Making sprites doesn't work until you have created a window with ScreenSize. Did you do that first?
Yeah, I did. I’ll look into it a bit more. Mainly working with PyQt5 and matplotlib and other libraries. Just started pygame because I can see that you can both make games and actually apply it to some drone programming.
Perhaps I scaled or did something wrong with my GIF as I just did some pixel animation in Aseprite..
Hello, whenever I try to implement this in, it comes back with the error: 'NameError: name 'makeSprite' is not defined'. Am I forgetting something here?
You have to install and import pygame_functions
Hi, please make a series on making a RPG game
why does my gif show up as a sliver
what does this mean?
line 569, in draw
surface_blit = surface.blit
AttributeError: 'str' object has no attribute 'blit
do i need to draw a rect or just put image?
send help pls
ok im fine now
@@HannazRolynn how do u fix it im having the same issue
@@lasscat9025 delete the rect u made and use the sprite no rect
hey my programme is going wayyy toooo fast anybody know anything to slow it down
Put a tick(30) command in your main loop to restrict it to 30 frames per second.
@@PagetTeaches thanks loveyour vids! But also one thing, I am having difficulty making the sprite jump! It sounds simple but please can you tell me the code because I really need it and dont know how to find y coordinate on pygame_functions! You can tell that I am new so please can you help me? one last thing is that i am making a 2D game so there is only going left and right (not up and dow). that is why i need your help! Please help.
great explanation sir!
Are you planning to add button function?
Good point. I know this would be useful. I suspect it would need some tweaks to the events handling of the current version, to allow functions to be attached to buttons.
I'll look into it.
@@StevePagetWorld thanks :)
why every 80ms? trying to understand.
The exact number isn't important. But a delay of 80ms means you get 12.5 frames of animation per second, which is roughly what is used in films like classic Disney or Stop Motion animation.
@@PagetTeaches thanks for replying, so basically just play with the number until it matches the animation / character velocity?
@@justsomedude5108 yep. If the speed of the feet seems to match the walking speed, that's about right.
Hi I can’t import pygame functions..
-> Method doesn’t exist.
Could you please help ? Ty
Python 3.7 / Pycharm / Pygame
Rengo L.
In the bottom of pycharm there is a button called terminal, click it.
When in the terminal type:
Pip install pygame
Then press enter. If that doesn’t work then idk how to do it.
Robobros 21 thank you ! I have done this before starting my project. Idk what’s going on, maybe this function has been integrated in another like : from pygame import locals *
?
@@rengol.4884 just do from pygame_functions import * and have the pygame_functions file in the same folder as your script
cool video! thanks
THIS IS EPIC!!!!!!!
Jesus Crist: Thanks dude!!
plssss help
you have no subscribers?
Last time I looked I had some! Maybe TH-cam is glitching?