I'm building a android app using pygame_sdl2, pygame, and pgs4a, and when I tried to run my app on my PC (as a Python File, not an android app), I got this error:
You can find my code here.
Thanks for your time, OrionDark7
I figured it out, as Remolten said, some parts of pygame have not been implented into pygame_sdl2. But here is an alternative:
First, don't load pygame_sdl2, just pygame, and then the surface will blit to the window.
From there, you can take a screenshot of the surface you are trying to blit, and save it as an image.
Re-import pygame_sdl2, and load the image instead.
This is what I have tried and it worked, pygame_sdl2 can display images, but not some shapes.
Related
I am new to game development. I am trying to start high and make a 3D RPG. I know the road is not gonna be easy. That is why i decided to use Ursina and python to make my game.
However i wanna add a cutscene showing a Backstory. I have the video in mp4 format but i cannot seem to know how to play it inside the game with Ursina.
Anyhelp will be much appreciated.
(Side question : do you think Ursina is good for a beginner in 3D gaming? If i want to publish my game on my website, isn't it better for me to learn javascript ? I read about Unity but it is too big to download for a little side project)
You can set the video as a texture of any element. You'll want to fix it to the UI using its parent attribute and you have to load the sound separately from the same file (as described in the Panda3D documentation).
from ursina import *
app = Ursina()
video = 'video.mp4'
video_player = Entity(model='quad', parent=camera.ui, scale=(1.5, 1), texture=video)
video_sound = loader.loadSfx(video)
video_player.texture.synchronizeTo(video_sound)
video_sound.play()
app.run()
The above code assumes that the video file is in the same folder as the Python script.
Well, I don't think there is a way to do that. the closest thing you can do to that is having a folder filled with all the frames of your video in .png or .jpg files, then adding a quad to the world and changing the texture of it to the next frame every fraction of a second depending on the framerate. this, however would make your computer l a g. trust me, I've tried it. it would probably be better to have a separate window with some sort of module that plays .mp4 files for playing the file.
In other words, there is no feasible way to do that.
From Entity Basics in the documentation:
e4 = Entity(model='cube', texture='movie_name.mp4') # set video texture
I made a very simple PyQt5 desktop app that plays a video. It works fine in Pycharm, which makes me suspect the code is fine and that the problem has something to do with Windows.
I used Pyinstaller to create an .exe file. Unfortunately after running the .exe, the app crashes briefly after opening with the video grayed out instead of playing.
The portion of code used to create the video:
# create link to movie file
movie_file = QtCore.QUrl.fromLocalFile('C:/Users/Owner/PycharmProjects/BF4 Deployment Timer/3d
video background 2.mp4')
media = QtMultimedia.QMediaContent(movie_file)
# create video widget
self.videoWidget = QtMultimediaWidgets.QVideoWidget()
self.setCentralWidget(self.videoWidget)
# media player object (video widget goes in media player)
self.mediaPlayer = QtMultimedia.QMediaPlayer(None,
QtMultimedia.QMediaPlayer.VideoSurface)
self.mediaPlayer.setVideoOutput(self.videoWidget)
# playlist
self.playlist = QtMultimedia.QMediaPlaylist()
self.playlist.setCurrentIndex(0)
self.playlist.setPlaybackMode(QtMultimedia.QMediaPlaylist.Loop)
self.playlist.addMedia(media)
# add content to media player
self.mediaPlayer.setPlaylist(self.playlist)
self.mediaPlayer.play()
The command window gives me the following error message:
DirectShowPlayerService::doSetUrlSource: Unresolved error code 0x80004005 (Unspecified error)
I have not been able to learn enough googling or on stack overflow to fix it, and it's a real challenge since I'm a fairly new programmer.
A solution or ideas for what to try are much appreciated!
SOLVED
Apparently QtMultimedia from PyQt5 relies on DirectShowPlayerService, for which you need to install a DirectShow decoder, such as LAV Filters. So, it was in fact a problem on my machine and not the program.
A basic install of LAV filters solved my video playback problems.
I found this answer after google translating this Chinese site:
https://blog.csdn.net/Wangguang_/article/details/93312629
LAV filters can be found here:
https://www.videohelp.com/software/LAV-Filters
I'm new to the turtle module and I'm having a problem while setting a background pic for my turtle project.
when running this code:
import turtle as tr
import os
os.chdir(pathname)
tr.setup(400,400)
tr.bgpic("diamond.gif")
I get an error message for the 5th line ending with:
_tkinter.TclError: image "pyimage4" doesn't exist
Sometimes it's pyimage2 doesn't exist or pyimage36. At each execution it changes.
I didn't find a real solution in other posts. Any help will be much appreciated.
You're not showing us your actual minimal code that fails as your example doesn't get past this line:
os.chdir(pathname)
since pathname isn't defined. I downloaded this GIF, renamed it diamond.gif, and ran the following subset of your code:
import turtle as tr
tr.setup(400, 400)
tr.bgpic("diamond.gif")
tr.done()
This displays the GIF in a window:
If you repeat what I did, and it works, then this may be a problem with your GIF file. (Download the GIF from this link, don't use my PNG illustration above.) If you repeat what I did and it doesn't work, then it may be a problem with your environment. This error message:
_tkinter.TclError: image "pyimage4" doesn't exist
is often associated with independently initializing both the turtle and the tkinter modules. If you aren't doing such, perhaps you're running in a specially tweaked environment that is. There may be a workaround, but you first need to determine what's really happening.
I am writing a kivy application, a game, which has an animated gif at the top which should play on a loop, as it does in finder etc. When it loads into the kivy gui it only shows one frame. I am new to kivy and would appreciate some help with this issue. I am using the .kv file to load the image:
Image:
source: 'spaceshipgif.gif'
allow_stretch: True
I have studied the documentation on the kivy website and searched around but to no avail.
I don't remember exactly what the gif playing status is - they should work in principle, but some of our providers are better than others at it. As I remember it might work better if you compile kivy with PIL as the image provider. I think some of these problems can be caused by technically incorrect gif files, which aren't handled well by the default provider, but I'm not sure about this.
A better solution is to instead put the frames of the .gif as images in a zip file, and set the path to this zip as the image path in your widget. Kivy will automatically animate them for you, including making it easy to change the animation rate (or pause it), without being limited by problems with gif files.
I am trying to get / set screen pixels (draw picture, line, circle, box, etc.) without starting x session. i tried google it but no success.
I am new to python. please help
I think the is no way to have graphics without x-session.
The best solution to this is to set boot to desktop and using pygame library create full screen window to draw graphics.