Python Turtle - How to make your own Sprites and Backround
What I need to say
Before you carry on, you must know how Turtle works, if you don't either watch videos, or read articles, or read my tutorials.
Tutorials if you need it
Python Turtle Module Tutorial 1 - https://repl.it/talk/learn/Python-Turtle-Module-Tutorial-1/59446
Python Turtle Module Tutorial 2 -
https://repl.it/talk/learn/Python-Turtle-Module-Tutorial-2/60312
Introduction
I used to think that Turtle couldn't add sprites, turtle can even make your own bg, I will show you how to draw and insert it in your repl file and use it, it is pretty simple if turtle is easy for you.
Step 1
Make a repl and import turtle, I only know how to do this in repl, I don't think it will work on python ide, so I use repl, also import turtle
Make a Sprite
First, your going to need to draw something, I use the website "Piskel.com"
- https://www.piskelapp.com/
It is actually a website to make gifs or animated stuff, but it can also be a picture if you just do one frame, it has all the tools.
Setting it up
Now in turtle, the width will be 800 and height will be 600, so you got to make a sprite like 50-100 pixels, but in piskel, on the resize canvas, if you put 800, 600, it will be 1600, 1200, so if your going to make a bg, do 400, 300, I will teach you how bg works later on.
In order to change the canvas size, on the very right of piskel, there are 5 boxes, click on the 2nd one starting from top, and change the width and height to 100, our character will be 200 pixels wide and high, now finish your character (Make sure to fill all the space)!
Getting the sprite on repl
Once your finished, on the very right again, the 4th box starting from top, (called the export box), keep it on gif, and click on download, then after a few seconds, you should get a file that has been downloaded called "New Piskel.gif", next step is easy, go back to repl, and drag the piskel file on the repl files, under main.py, hold m1 on the piskel file and drag it there, now you should see a new file on your repl, now click on it, and you will see your sprite, finish setting up your code
#Import import turtle #Setup wn = turtle.Screen() wn.setup(800, 600)
also rename the piskel file you put on repl to whatever you desire, I will call it "character.gif", keep the gif there.
now you don't want to write "character.gif", everywhere, so make it shorter do
char = "character.gif"
Now, you will need to make a Char = turtle.Turtle()
but once you do
Char.shape(char)
turtle won't detect that as a shape, so you got to make it a shape, before that do
wn.addshape(char)
Now you made it into a shape, now you can add your character, if it didn't work, ask a question in the comments.
Creating background
in order to create the bg, it will be different this time, make the piskel 400 by 300, now, when you write 400, the other will be 400, so turn of "Maintain aspect ratio"
Now just draw a backround, and import it to repl, like you did with the sprite, now rename it, and all you have to do is:
wn.bgpic((Your Background .gif name)
if reader == "liked":
print("Please Upvote if you want")
if reader == "disliked":
print("Please say why")
if reader == "confused":
print("Please ask a question")
@DominicHuieWhit, if you got any questions, ask me :)
only shows the first frame in a gif
@NoahWisniach it is only supposed to show the first frame of a gif.
Traceback (most recent call last):
File "main.py", line 7, in
Char.shape(char)
NameError: name 'Char' is not defined
capitalization I [email protected]
@CoahWilson show me the code.
the tutorial really helped I was confused about how to do this for the longest time. also, is it possible for keybinds to work? and I love the ending lol, I love piskel and I actually made my profile pic with it.
@JacobSedgebeer, I don't know, I don't use turtle anymore, if your interested in game dev, download godot game engine, it has a language similiar to python and it has a fast download, unlike unity.
@CodersXD okay thanks!