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

Поділитися
Вставка
  • Опубліковано 28 сер 2024
  • 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

КОМЕНТАРІ • 118

  • @AltunKARIMLI
    @AltunKARIMLI 10 днів тому +1

    Short and precise. Thank you. If you have pygame/pygbag game, go ahead and use this video.

  • @Ka05aR
    @Ka05aR Рік тому +3

    This Specific Video helps me a million...

  • @Oxxyjoe
    @Oxxyjoe 3 місяці тому

    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.

  • @Multiverseofcoding2129
    @Multiverseofcoding2129 Місяць тому +1

    This is just OP

  • @n4p3r0
    @n4p3r0 Рік тому +1

    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

  • @frazebean5117
    @frazebean5117 9 місяців тому +1

    Thanks for the tutorial!

  • @awesomefacts101
    @awesomefacts101 Рік тому +12

    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

  • @audevstin
    @audevstin 16 днів тому +2

    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  15 днів тому

      Not sure, maybe you are using some unsupported function in wasm, try asking on the discord channel: discord.com/channels/772505616680878080/971360806287577098

  • @exe4660
    @exe4660 Рік тому +3

    can i use pygbag to import the package "pygame widgets" ?

  • @apex-hybrid
    @apex-hybrid Рік тому +3

    for some reason my always says last argument must be app level directory. I have followed your example but isnt working sadly

  • @cycl0ne154
    @cycl0ne154 6 місяців тому

    I think the difference between your local FPS and the one in WASM is the browser. Browser limits everything to 60 FPS.

  • @oroshi858
    @oroshi858 4 місяці тому

    thank you ! very usefull

  • @NightSquadShorts
    @NightSquadShorts 2 місяці тому +1

    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 Місяць тому

      I am also stuck on a black screen, have you found a fix?

  • @alexandertownsend5079
    @alexandertownsend5079 Місяць тому

    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.

  • @stoufa
    @stoufa 11 днів тому +1

    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  11 днів тому

      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

  • @arcade-fighter
    @arcade-fighter 6 місяців тому

    Many thanks for the tutorial! Does this virtual machine have network support ?

  • @user-jw3fu6yx7g
    @user-jw3fu6yx7g Рік тому

    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?

  • @miguelxd4133
    @miguelxd4133 Рік тому +1

    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

  • @baharkarimi2040
    @baharkarimi2040 Рік тому +1

    Can I send a pygame to an API in real-time?

  • @esrasoner9319
    @esrasoner9319 Рік тому +1

    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 9 місяців тому

      I have that error too! Did u ever get it fixed?

  • @mohiuddinsyed1684
    @mohiuddinsyed1684 Рік тому +1

    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

  • @mac0cheese763
    @mac0cheese763 Рік тому +1

    So if my pygame game uses libraries such as openAI gym Pygbag wouldn't work?

    • @FinFET
      @FinFET  Рік тому

      probably not, maybe in the future

  • @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.

  • @Monstaus23Roblox
    @Monstaus23Roblox 8 днів тому +1

    My project using def to run GUI! What should I do?

    • @FinFET
      @FinFET  8 днів тому

      Not sure, you could try asking on the discord channel: discord.com/channels/772505616680878080/971360806287577098

    • @Monstaus23Roblox
      @Monstaus23Roblox 8 днів тому

      @@FinFET i got it before! But thanks for your help

  • @SkyFly19853
    @SkyFly19853 2 роки тому +2

    Pybag? Like in the bag?... 🤔😏

    • @FinFET
      @FinFET  2 роки тому +1

      Yeah, I found the name funny too 😂

    • @SkyFly19853
      @SkyFly19853 2 роки тому

      @@FinFET
      How about they call it Pyweb?... why not?... 🤔😏

  • @videomenish
    @videomenish Рік тому +1

    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

  • @usuariodefectuoso4046
    @usuariodefectuoso4046 Рік тому +1

    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

  • @user-oj6df1wv9b
    @user-oj6df1wv9b 10 місяців тому

    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?

  • @rubylikessonic2
    @rubylikessonic2 Рік тому +1

    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

  • @drm8164
    @drm8164 Рік тому +1

    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 :)

  • @Equilibrier
    @Equilibrier Рік тому +2

    Thank you, I was searching for something like this. Wonder if this would also work with dearpygui.

  • @Anomalous-ye3hi
    @Anomalous-ye3hi 5 місяців тому

    Is it possible to play the games on a self hosted domain??

  • @randomguy6150
    @randomguy6150 9 місяців тому

    thank you

  • @aintNexus
    @aintNexus 2 роки тому +2

    I still didn't see the whole vid, but i bet It Will be Amazing!

    • @FinFET
      @FinFET  2 роки тому +1

      The possibility to run my games made with pygame directly in the browser is amazing for me =)

    • @aintNexus
      @aintNexus 2 роки тому +1

      @@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 роки тому +1

      @@FinFET Yep!

  • @sushovanpal538
    @sushovanpal538 2 роки тому

    sa,e bro tNice tutorials is fire

  • @kimgeraghty8873
    @kimgeraghty8873 Рік тому +3

    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  Рік тому +1

      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

  • @hardikbabbar73
    @hardikbabbar73 Рік тому

    Does pygbag work with GPIO pins on the raspberrypi?

  • @stickpal
    @stickpal Рік тому +2

    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  Рік тому +1

      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  Рік тому +1

      @@stickpal are you using .ogg files?
      newer versions of pygbag only support ogg for now

    • @stickpal
      @stickpal Рік тому +1

      @@FinFET I'am using .mp3. thanks for the help, ill see if it fixes it.

    • @stickpal
      @stickpal Рік тому +1

      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.

  • @bruhwantedboosiefade69
    @bruhwantedboosiefade69 Рік тому +1

    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

  • @EliasXD2009
    @EliasXD2009 Рік тому +1

    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 Рік тому +1

      @@FinFET Thank you very much!!!

  • @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 4 місяці тому

      Little late but put your game loop in a main function and call the main function

  • @michelleblackrose
    @michelleblackrose Рік тому +1

    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

  • @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 Рік тому +1

      @@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...

  • @hyperdusstuff5874
    @hyperdusstuff5874 Рік тому +1

    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

  • @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

  • @alperklc7782
    @alperklc7782 Рік тому

    thaks

  • @hell_for_hell
    @hell_for_hell 9 місяців тому

    where are you coding this?

  • @maximusachoo
    @maximusachoo Рік тому +1

    pybag not found?

    • @FinFET
      @FinFET  Рік тому

      try "pygbag" instead 😉

  • @Toda_Ciencia
    @Toda_Ciencia Рік тому +1

    Does it works in macOS?

    • @FinFET
      @FinFET  Рік тому

      Should work in any modern browser

  • @annuayXD
    @annuayXD Рік тому

    Can i Get this website's Templete Code

    • @FinFET
      @FinFET  Рік тому

      Like this one? github.com/FinFetChannel/yarc

  • @GLAWKG0D
    @GLAWKG0D Рік тому +1

    I love you more and more

  • @kizsuko
    @kizsuko 2 роки тому +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

  • @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  Рік тому +1

      @@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 Рік тому +1

      @@FinFET thanks for your help man :)

    • @goosew3266
      @goosew3266 Рік тому +1

      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 роки тому +1

      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 роки тому +1

      @@FinFET great thank you for the precision

  • @teehamster0099
    @teehamster0099 2 роки тому

    bro

  • @_black_stack_9914
    @_black_stack_9914 4 місяці тому

    DON'T WORK! DISLIKE!