Running PyGame in the web browser with Pygbag! mini Python tutorial Wasm WebAssembly

  Рет қаралды 32,739

FinFET

FinFET

Күн бұрын

Pygbag is a library that packages PyGame games made in Python to run in the browser using CPython wasm webassembly. It is really easy to use and deploy your games on the web, for example, on itch!
"It uses a CPython interpreter built on webassembly, and a static build of pygame on webassembly, using SDL and SDL_image and things on webassembly
Pygame’s dependencies already supported emscripten/webassembly
CPython 3.11 (upcoming) can be built for the web without needing patches, thanks to some core developer work"
Relevant links:
pypi.org/proje...
pygame-web.git...
itch.io/c/2563...
/ discord

Пікірлер: 119
@psxalx128
@psxalx128 6 күн бұрын
Thank you, straight to the point and easy to follow. Worked for my project straight away
@AltunKARIMLI
@AltunKARIMLI Ай бұрын
Short and precise. Thank you. If you have pygame/pygbag game, go ahead and use this video.
@Ka05aR
@Ka05aR Жыл бұрын
This Specific Video helps me a million...
@Oxxyjoe
@Oxxyjoe 4 ай бұрын
This is great stuff!!! I discovered this today and am really excited. I can't upload my web game yet, because judging is still going on for the game jam I entered in, and, putting a web version of the game up would potentially be like updating it beyond the deadline. So it will have to wait until next week but man, it's so cool that pygbag exists.
@frazebean5117
@frazebean5117 10 ай бұрын
Thanks for the tutorial!
@Multiverseofcoding2129
@Multiverseofcoding2129 2 ай бұрын
This is just OP
@n4p3r0
@n4p3r0 Жыл бұрын
This is so cool thanks :) Bot for some reason it made it so that all my random values turned into set values
@FinFET
@FinFET Жыл бұрын
this is by design I think, to make testing easier, you can circumvent this by calling random.seed() with something like mouse position or time
@awesomefacts101
@awesomefacts101 Жыл бұрын
This is super cool and easy to use so ty for making this vid. Saw some webassembly for c++, but python is like 10x easier in pretty much every aspect so this is really helpful all in all tytytytytytytytytytytyty tytytytytyt tytytytyty tytytyty tyty tyt ytyt ytyty tyt ytyt y
@guy-
@guy- Жыл бұрын
Ytyyttytty
@safehaven2022
@safehaven2022 Жыл бұрын
This was helpful. Thanks a lot
@apex-hybrid
@apex-hybrid Жыл бұрын
for some reason my always says last argument must be app level directory. I have followed your example but isnt working sadly
@SudhaRani-or1pm
@SudhaRani-or1pm Жыл бұрын
Yeah mine too can anyone help w that
@NightSquadShorts
@NightSquadShorts 3 ай бұрын
I am stuck on a black screen maybe because my game has multiple functions for screens like, home_screen, welcome_screen, game_screen. Can you help me?
@dmdotpy
@dmdotpy 2 ай бұрын
I am also stuck on a black screen, have you found a fix?
@audevstin
@audevstin Ай бұрын
Dosen't work for me, when I run the pygbag command it says: WARNING: wasm mimetype unsupported on that system, trying to correct
@FinFET
@FinFET Ай бұрын
Not sure, maybe you are using some unsupported function in wasm, try asking on the discord channel: discord.com/channels/772505616680878080/971360806287577098
@cycl0ne154
@cycl0ne154 7 ай бұрын
I think the difference between your local FPS and the one in WASM is the browser. Browser limits everything to 60 FPS.
@exe4660
@exe4660 Жыл бұрын
can i use pygbag to import the package "pygame widgets" ?
@oroshi858
@oroshi858 5 ай бұрын
thank you ! very usefull
@arcade-fighter
@arcade-fighter 7 ай бұрын
Many thanks for the tutorial! Does this virtual machine have network support ?
@alexandertownsend5079
@alexandertownsend5079 2 ай бұрын
My game doesn't have a main() function. I can play it on my computer just fine so I know the code works in that context, but will that make a difference when I upload it? Basically, how I wrote my game was I imported pygame. I did pygame.init().Then I defined all my game variables. Then all the relevant functions telling the computer how to draw assets and play sounds. Lastly I called all of the functions in the while loop and wrote some code in the event handler. Do I need a main function? Also what does async refer to? I am not familiar with Javascript. I only Python and I am relatively new to it.
@АнтонПод
@АнтонПод Жыл бұрын
Thanks for the cool video! Everything works fine, but if I use not the built-in pygame surfaces, but images - a black screen. Where is it worth a look?
@stoufa
@stoufa Ай бұрын
my game works fine locally but I can't get its web export to work (I'm getting a black screen), have any of you faced this problem before?!
@FinFET
@FinFET Ай бұрын
You can try adding #debug to the end of the address to see if there is any error msg. You can also get great help on discord discord.com/channels/772505616680878080/971360806287577098
@shantelwilliams1822
@shantelwilliams1822 Жыл бұрын
I got mines to run but it only plays the music and doesn't show any of my graphics. I have to figure it out.
@baharkarimi2040
@baharkarimi2040 Жыл бұрын
Can I send a pygame to an API in real-time?
@miguelxd4133
@miguelxd4133 Жыл бұрын
hello! im using a state changer with multiple functions, not a class, just multiple functions, and the functions dont seem to be getting called for some reason, it just stays on the menu
@FinFET
@FinFET Жыл бұрын
the functions that have an infinite loop have to be async and be awaited, but hard to say without taking a look at the code. You can get better help on discorf discord.com/channels/772505616680878080/971360806287577098
@mohiuddinsyed1684
@mohiuddinsyed1684 Жыл бұрын
The discord link in your description and about has expires Use a non-expiring one I have a problem with building my code to web, I need help
@FinFET
@FinFET Жыл бұрын
sorry, I'm new to discord, here is a non expiring link discord.gg/h7gVZZEKW3
@randomguy6150
@randomguy6150 10 ай бұрын
thank you
@videomenish
@videomenish Жыл бұрын
Is it possible to add a game to your own website so that it runs there? And not only worked on the local server.
@FinFET
@FinFET Жыл бұрын
Not sure how to do something like that, but probably you would have a bit of lag
@mac0cheese763
@mac0cheese763 Жыл бұрын
So if my pygame game uses libraries such as openAI gym Pygbag wouldn't work?
@FinFET
@FinFET Жыл бұрын
probably not, maybe in the future
@sushovanpal538
@sushovanpal538 2 жыл бұрын
sa,e bro tNice tutorials is fire
@SkyFly19853
@SkyFly19853 2 жыл бұрын
Pybag? Like in the bag?... 🤔😏
@FinFET
@FinFET 2 жыл бұрын
Yeah, I found the name funny too 😂
@SkyFly19853
@SkyFly19853 2 жыл бұрын
@@FinFET How about they call it Pyweb?... why not?... 🤔😏
@usuariodefectuoso4046
@usuariodefectuoso4046 Жыл бұрын
i get this error message when running on the browser: Error occurred: Unexpected reserved word. Can someone help me pls?
@FinFET
@FinFET Жыл бұрын
never seen this one, maybe someone on discord could help
@Reddysupreme
@Reddysupreme Ай бұрын
My project using def to run GUI! What should I do?
@FinFET
@FinFET Ай бұрын
Not sure, you could try asking on the discord channel: discord.com/channels/772505616680878080/971360806287577098
@Reddysupreme
@Reddysupreme Ай бұрын
@@FinFET i got it before! But thanks for your help
@stickpal
@stickpal Жыл бұрын
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.
@FinFET
@FinFET Жыл бұрын
Hard to say without taking a look at the code, maibe you forgot to await asyncio.sleep(0) after updating the screen? In discord you can get better help: discord.com/channels/772505616680878080/971360806287577098
@stickpal
@stickpal Жыл бұрын
@@FinFET The main error was this line: Task exception was never retrieved future: Traceback (most recent call last): File "", line 230, in main pygame.error: Surface doesn't have a colorkey. when taking a look at line 230 it's related to a sound file for when the player makes collision with a pipe.
@FinFET
@FinFET Жыл бұрын
@@stickpal are you using .ogg files? newer versions of pygbag only support ogg for now
@stickpal
@stickpal Жыл бұрын
@@FinFET I'am using .mp3. thanks for the help, ill see if it fixes it.
@stickpal
@stickpal Жыл бұрын
update, I did try switching to .ogg, pygame didn't work at all, and no even the background music would play when i try running pygbag.
@drm8164
@drm8164 Жыл бұрын
Please help: i have a game done with computer vision with Pycharm, how to upload it in my web-site? Thanks in advance.
@FinFET
@FinFET Жыл бұрын
I'm not sure if that is possible yet, you probably rely on a library like opencv which isn't supported by pygbag at the moment
@drm8164
@drm8164 Жыл бұрын
@@FinFET thank you for you answer :)
@alperklc7782
@alperklc7782 2 жыл бұрын
thaks
@hardikbabbar73
@hardikbabbar73 Жыл бұрын
Does pygbag work with GPIO pins on the raspberrypi?
@KyleHiers-p6p
@KyleHiers-p6p 11 ай бұрын
I am getting a grey screen and the following message: WARNING: wasm mimetype unsupported on that system, trying to correct Not using SSL can anyone fix this?
@esrasoner9319
@esrasoner9319 Жыл бұрын
Great tutorial thanks a lot but im getting this error. Does someone has an idea? Traceback (most recent call last): File "", line 25, in pygame.error: Surface doesn't have a colorkey
@jamespineiro736
@jamespineiro736 10 ай бұрын
I have that error too! Did u ever get it fixed?
@Equilibrier
@Equilibrier Жыл бұрын
Thank you, I was searching for something like this. Wonder if this would also work with dearpygui.
@rubylikessonic2
@rubylikessonic2 Жыл бұрын
It works for me but it's a lot slower than when I run it normally, is there any fix or reason for it?
@FinFET
@FinFET Жыл бұрын
for me it is usually about 3 to 5x slower, make sure to not have any prints or logs enabled, also, it is limited to your monitor refresh rate
@Anomalous-ye3hi
@Anomalous-ye3hi 6 ай бұрын
Is it possible to play the games on a self hosted domain??
@amj.composer
@amj.composer 11 ай бұрын
wait....I don't even have a main function! I just have the game loop and a couple classes before that! WDID?
@bennettmarshall9525
@bennettmarshall9525 5 ай бұрын
Little late but put your game loop in a main function and call the main function
@aintNexus
@aintNexus 2 жыл бұрын
I still didn't see the whole vid, but i bet It Will be Amazing!
@FinFET
@FinFET 2 жыл бұрын
The possibility to run my games made with pygame directly in the browser is amazing for me =)
@aintNexus
@aintNexus 2 жыл бұрын
@@FinFET Nice, but for me... I think It could explode
@FinFET
@FinFET 2 жыл бұрын
I also think so, it is way more convenient for sharing
@aintNexus
@aintNexus 2 жыл бұрын
@@FinFET Yep!
@kimgeraghty8873
@kimgeraghty8873 Жыл бұрын
Hi! thanks for the awesome video! this was a literal game changer. Do you have any advice for how to get the game to work on iphone too? I selected mobile friendly in the frame options but is there something else that should be done? I have it working in the browser on the computer but not on my iphone. It says: compileError: webAssembly.Module doesn't parse at byte 753386: references are not enabled. Appreciate any insights you can share!
@FinFET
@FinFET Жыл бұрын
Never tried it on an Iphone, not sure what the error means. You can get bette help on the pygame-web channel on discord: discord.com/invite/h7gVZZEKW3
@EliasXD2009
@EliasXD2009 Жыл бұрын
how did you transform the python file to apk for the play store?
@FinFET
@FinFET Жыл бұрын
That was with buildozer, check out my newest video
@EliasXD2009
@EliasXD2009 Жыл бұрын
@@FinFET Thank you very much!!!
@jonathanjonathansson3695
@jonathanjonathansson3695 Жыл бұрын
How do i set up the environment variable for pygbag? I'm just trying to make the basic example on gitlab work and I can't get past the "'pygbag' is not recognized as an internal or external command, operable program or batch file."-error :(
@FinFET
@FinFET Жыл бұрын
try using: python -m pygbag foldername
@jonathanjonathansson3695
@jonathanjonathansson3695 Жыл бұрын
@@FinFET Firstly, thanks for replying! Secoundly, unfortunately this prompts me with "No module named pygbag", but I have installed pygbag. This is what I've done: 1) pip install pygbag 2) pip3 install pygbag --user --upgrade 3a) pygbag foldername "The term 'pygbag' is not recognized as the name of a cmdlet" 3b) python -m pygbag foldername "No module named pygbag" should this work or am I missing some step?
@FinFET
@FinFET Жыл бұрын
@@jonathanjonathansson3695 you could try finding the folder where pygbag was installed, but honestly, I think it might be easier to reinstall python making sure to check the option to add python to the path, then reinstall the libraries you need
@FinFET
@FinFET Жыл бұрын
@@jonathanjonathansson3695 no module named pygbag? thats weird, have you more that one version of python installed? maybe a misspell like pybag instead of pygbag...
@michelleblackrose
@michelleblackrose Жыл бұрын
Hi great video i was hopping someone could help me when i launch the server I only get a black screen after download if I post my code could someone look at it as I am a complete newbie to Python and programing Thanks
@FinFET
@FinFET Жыл бұрын
Hi Michelle, try adding #debug to the address in the browser, maybe there is an error loading a module or a file You can get better help on discord: discord.com/channels/772505616680878080/971360806287577098
@maximusachoo
@maximusachoo Жыл бұрын
pybag not found?
@FinFET
@FinFET Жыл бұрын
try "pygbag" instead 😉
@hell_for_hell
@hell_for_hell 10 ай бұрын
where are you coding this?
@GLAWKG0D
@GLAWKG0D Жыл бұрын
I love you more and more
@hyperdusstuff5874
@hyperdusstuff5874 Жыл бұрын
mine is stuck on 'downloading', any help?
@FinFET
@FinFET Жыл бұрын
try adding #debug tho the end of the address to see if there is any error msg, you can get more help on discord too discord.gg/h7gVZZEKW3
@hyperdusstuff5874
@hyperdusstuff5874 Жыл бұрын
@@FinFET all fixed (mostly) i have the game running on itch, but my threaded functions aren't threading at all. does threading work at all in pygbag ?
@FinFET
@FinFET Жыл бұрын
@@hyperdusstuff5874 I think it should, but I'm no expert, you have make it all async if I'm not mistaken, Paul, the creator of pygbag, can help you with that on discord
@Toda_Ciencia
@Toda_Ciencia Жыл бұрын
Does it works in macOS?
@FinFET
@FinFET Жыл бұрын
Should work in any modern browser
@kizsuko
@kizsuko 2 жыл бұрын
I an I understand it when he's sayin it but i can't do it myself
@FinFET
@FinFET 2 жыл бұрын
come to the discord server, there are more experienced people that can help to sort things out
@FinFET
@FinFET 2 жыл бұрын
discord.gg/W2QpxF4N
@annuayXD
@annuayXD Жыл бұрын
Can i Get this website's Templete Code
@FinFET
@FinFET Жыл бұрын
Like this one? github.com/FinFetChannel/yarc
@goosew3266
@goosew3266 Жыл бұрын
I am getting ModuleNotFoundError: No module named 'sqlite3'
@FinFET
@FinFET Жыл бұрын
Try installing it with pip
@goosew3266
@goosew3266 Жыл бұрын
@@FinFET yeah it's a tricky one ay. sqlite is actually an inbuilt library in python. it has been since python 2.7 and something. i have tried installing with pip, but says already installed. the program works if i just run it in python, but as soon as I use pygbag, and it runs it on my local host, I get this error when checking the debug on the browser
@FinFET
@FinFET Жыл бұрын
@@goosew3266 humm, so you are using it inside your game? maybe the guys at discord can help, not sure if possible yet discord.gg/pygame
@goosew3266
@goosew3266 Жыл бұрын
@@FinFET thanks for your help man :)
@goosew3266
@goosew3266 Жыл бұрын
I got it working. I needed to use the binary module. So all i had to change was: import sqlite to: import _sqlite
@bossgd100
@bossgd100 2 жыл бұрын
Its fast or not ?
@FinFET
@FinFET 2 жыл бұрын
In my testing it is about 5 times slower than regular pygame, but in the future it might become faster by better utilizing webassembly and javascript features
@bossgd100
@bossgd100 2 жыл бұрын
@@FinFET great thank you for the precision
@teehamster0099
@teehamster0099 2 жыл бұрын
bro
@_black_stack_9914
@_black_stack_9914 4 ай бұрын
DON'T WORK! DISLIKE!
@bruhwantedboosiefade69
@bruhwantedboosiefade69 Жыл бұрын
My program stops at 2:38 and I have been waiting for 20 minutes. help
@FinFET
@FinFET Жыл бұрын
have you tried using the debug page? localhost:8000/#debug You can get better help on the pygame-web channel on discord: discord.com/invite/h7gVZZEKW3
@minecrafmasterpl
@minecrafmasterpl Жыл бұрын
I get the "no such file or directory" error while launching in pygbag localhost. When i run the script in pygame window locally everything works fine. Do you know that the issue is caused by?
@FinFET
@FinFET Жыл бұрын
try: "python -m pygbag gamefolder" instead
@minecrafmasterpl
@minecrafmasterpl Жыл бұрын
@@FinFETI already did that. The Game launches for localhost, but the error is displayed when i go to localhost:8000#debug i can see that the issue displayed is "no such file or directory"
@FinFET
@FinFET Жыл бұрын
@@minecrafmasterpl I see, try loading all assets inside the main script, also sometimes inverting the \ to / in the file path string you can get better help on the pygame-web channel on discord: discord.com/invite/h7gVZZEKW3
Export Python pygame Game to Web with WebAssembly (pygbag tutorial)
7:07
Programming With Nick
Рет қаралды 25 М.
I Paid Fiverr Game Developers to Make the Same Game
10:25
BadGameDev
Рет қаралды 697 М.
Apple peeling hack @scottsreality
00:37
_vector_
Рет қаралды 130 МЛН
АЗАРТНИК 4 |СЕЗОН 2 Серия
31:45
Inter Production
Рет қаралды 1,1 МЛН
GIANT Gummy Worm Pt.6 #shorts
00:46
Mr DegrEE
Рет қаралды 78 МЛН
From Small To Giant Pop Corn #katebrush #funny #shorts
00:17
Kate Brush
Рет қаралды 68 МЛН
Why Are Open Source Alternatives So Bad?
13:06
Eric Murphy
Рет қаралды 640 М.
If You Can't Make Games After This Video, Give Up
4:37
Fredyy
Рет қаралды 928 М.
How Google's Chromium Took Over the Browser World
9:59
Eric Murphy
Рет қаралды 317 М.
Creating a DOOM (Wolfenstein) - style 3D Game in Python
52:00
Coder Space
Рет қаралды 1,3 МЛН
Using AI to NEVER LOSE in KAHOOT
10:54
The Coding Sloth
Рет қаралды 881 М.
Making a Game in Python with No Experience
5:57
Goodgis
Рет қаралды 1,7 МЛН
Why use Pygame instead of a Game Engine? Gamedev Python
8:04
What is the Smallest Possible .EXE?
17:04
Inkbox
Рет қаралды 395 М.
Can I Run Youtube Entirely From My Terminal? (No Browser)
15:31
Apple peeling hack @scottsreality
00:37
_vector_
Рет қаралды 130 МЛН