Export Python pygame Game to Web with WebAssembly (pygbag tutorial)
Вставка
- Опубліковано 17 лип 2024
- Export your Python Game to Web with WebAssembly.
Snake game code: github.com/educ8s/Python-Retr...
Try it online: paixnidakia.gr/snake
Bluehost Web Server: bit.ly/BluehostAccount
💖 Full disclosure: The above link is an affiliate link. I get a small percentage of each sale it generates. Thank you for your support!
0:00 Intro
0:24 How to share your game
1:35 Convert to WebAssebly
2:48 Install pygbag
3:20 Changes to the code
4:27 Conversion
4:59 Testing the result
5:44 Build Folder
Exporting pygame games to wasm is new for me! Thanks for the detailed video. Great work :)
Best video I could found about this. Thank you!!
I got more information form a 2 hour video for this 10min video! crazy keep it up
I still can't believe this, this is an incredible invention
Thank you Nick, that was new to me, it's amazing what todays web browsers can handle these days, soon all apps will be web based.
You're welcome! I'm glad to hear that you found the information useful and that it was new to you. It's true that web browsers have come a long way and can handle more and more advanced features. I think it's exciting to see how web-based apps are becoming more and more prevalent in the industry. Thanks for your comment!
does it only work when your entire game is in a single file? Been stuck on "Setting [src] up" where 'src' is the name of my directory.
what if the game loop is part of the main game class?
It (as well as pyinstaller if I don’t put It into the directory layer above the rest of the game) seemingly can’t find the font I’m importing. Why do all compiling programs struggle with fonts so much?
Im trying to do this on a raspi over a LAN connection. Ive done this and it works on localhost however, id like to be able to display it on some page like you have in the end. Ive got apache on the pi to work, but how can i run the game this way? Does the python file need to be an APK? I cannot find anything online explaining how to do this
Thank you Nick!
I have a programe to edit images. It use Tkinter for the GUI. And PIL library. In this case, PyBag don't include these libraries. What can I do to achieve a similar result? Pyscript neither do. Maybe use a remote server to run it would be the unique solution?
My html file created by pygbag is full of errors. I could fix them. But, even the, the game doesn't work for me after the emerging banner Pygame. After that, it only appear a black box. Could be possible if anybody share a succesfull generated .html file?
It is showing black screen on me, anybody know the issue? I try with the snake example and also try on my game. the background music is played but the graphics, input, and sfx is not. just black screen
What if my game has 3 main definitions, play, main menu and tutorial?? how do I include async with it ? When i try to do async def with tutorial function, I cant change to any of the other screens anymore.
the image is black clompledly black, do I need to upload my background too?
it isn't working!!!!!
Thanks it's a good tutorial
does this work with numpy and numba?
Do you know how to use c++20 modules with raylib
i successfully completed the instruction but as soon as i interact with my game, there seems to be a light blue overlay pver my game (similar to how it looks like when you select and image/ or text) how can i fix this?
Nick the GOAT
am getting the following error: "WARNING: wasm mimetype unsupported on that system, trying to correct
Not using SSL"
could not find a solution anywhere
did u find the solution?
he got the same thing and it still ran
The browser shows blank screen after ready to start button, The game has no error while running normally
what could be possible cause?
same thing is happening with me
did u find the solution for it?
when running the game i get the error: Unexpected reserved word
You sound Spanish or Greek 🤔
Great tutorial, man. Thank you!
Great explanation, I manage to load the game in the browser, but only when the command prompt is open, after I close the command prompt and double click on the browser icon in the build, the browser fails to load the game
Yes, that's normal behavior. The command promt has created a game server to load the game. If you close the command prompt, the server is no longer active so the game won't load. If you upload the game to your own web server it will work fine, this issue happens only if you run the game locally.
thanks so much
Hey, I tried doing this with my own flappy bird clone, For some reason pygbag kept showing black screens, only the background music loads, I've also tried using the debug tool that comes with pygbag but it only showed errors that didn't really make sense cause they worked in pygame. Do you have any idea how I could fix this?
Thanks.
What is your music format? MP3 or something else? I had the same problem when using .mp3 files. When I converted them to .ogg everything works fine. Try it and tell me how it goes.
@@programmingwithnick Hey, I did fix it after all, Basically the sound files weren't converted properly to .ogg, hence why the game wouldn't boot. and I have also forgotten to add a await asyncio.sleep(0) after every while true loop.
I love your voice
pygbag snake not working with giving me an erorr
ty🙏
All I see on screen after the green loading bar is a black screen and I can hear audio. Also it’s not the whole screen just the game tab. How do I fix this
same
did u find the solution
@@prajwalshetti3655 I’m pretty sure I did but I don’t remember.
Hey, I have installed pygbag, but when I run "pygbag [Folder]," I get an error message that says pygbag is not an executable internal or external exam.
im having the exact same issue. i have no idea how to fix it.
@@D-ingus I think i found the solution. Try running python -m pygbag [Folder]
Thanks Dude U help me alot
@@elainegou
Thank you I can now participate in Pirate Software - Game Jam 15 😁
edit: My screen is now black with no game play why?
my screen is black after I click start, any suggestion?
There are many things that can go wrong. First you could try the debug mode to see what's wrong using localhost:8000#debug instead of just localhost:8000
it will show you the REPL with any message/trace python could send.
@@programmingwithnick I substituted the mp3 files with ogg and now it works
FAQ 1: All I get is a black screen after converting the game.
Please load the game like this: localhost:8000/#debug
This way you can see the error that prevents the game from loading.
FAQ2: Can I use .mp3 files?
Yes, but don't. Using .mp3 files is buggy. Convert your .mp3 sound to .ogg.
*Should I assume playing videos is also not a good idea?*
Is there a way this can work on iPhones? When I try the link I get the screen with the green button that says “Ready to Start!” but it does nothing when I tap on it.
Yes, this happens if the game you have created requires a keyboard to work. Since there is no physical keyboard on the iphone this approach won't work. You have to modify your original code to include mouse controls or touch controls as well.
@@programmingwithnick thank you!
I have a issue of the game just showing previous images. The game runs but in a totally crazy way. any ideas?
Solved. It happened because I was calling the run async method by inside a __init__() function of a class. Do not do that. I create a class and than called its run method from out of the init function
@@SalocinRevenge Iam getting a black screen
I got the ready button but its not going further
what could be the problem?
Iam calling the async normally
when i open the game in the browser it doesn't start and screen is black
same thing is happening with me
did u get the solution?
Same
awesome
I really would appreciate if you can do a similar tutorial but for C++ with Raylib.
Added to the list. Thanks!
Iam getting a black screen
I got the ready button but its not going further
what could be the problem?
Hi, I had the same problem and then realized I put the await asyncio.sleep(0) at the end of the main() function and not inside the while loop... I hope this helps you out. Now I just need to figure out how to upload it to my website
@@calendollens9982 Thank you so much for ur help. I got the output :)
hey nick, some people are having some dificulties, can you make and pin a comment listing some problems and how to solve them? will help a lot
I have installed pygbag but I'm still getting:
C:\Users\aryam\Desktop>pygbag snake
'pygbag' is not recognized as an internal or external command,
operable program or batch file.
What do I do?
have the same problem
@@cypherecon5989 python -m pygbag file_name use this command and error will resolve
Freezes at Downloading on localhost
same problem, doesn't display the program on the web browser, rather shows a black screen
Try loading the game like this: localhost:8000/#debug to see what goes wrong.
😊
Please nick can you make more tutorials about raylib
Yes, I will make more raylib tutorials, but please be patient. Long format tutorials require a lot of time to be produced!
@@programmingwithnick sure but we need it the documentation is just a cheat she
Thank you very much for the feedback. I noted it down. I will prepare a lot of tutorials about raylib since you guys want it! Stay tuned!
@@programmingwithnick trust me Nick..... you gonna blow up in no time