so im building a simple paint program in python as a project, using Pygame it works by basically drawing a stream of circles when the mouse gets pressed and you drag it around the surface, its got a couple other little things going on but the thing i wanna ask is, is there a way to change the singular mouse input you know mouse.get_pressed to either multiple mouse inputs at one time or a multi-touch input into the point list that's streaming the circles.
running= True
while running:
if buttons[0] == True:
x,y = pygame.mouse.get_pos()
if x> PA+AS:
xShift = x - PA - AS
pygame.draw.circle(pArea,DRAW_CLR,(xShift,y),BRUSHSIZE)
pygame.display.flip()
so this is the part of the code i really want to change more or less. just so that instead of just one mouse, i could use my touchscreen to draw with maybe two finger
Latest versions of pygame support multitouch input (and I believe also gestures).
The events which control it are pygame.FINGERDOWN, .FINGERUP and .FINGERMOTION. My understanding is that they work like mouse inputs, but can be multiple and can be distinguished by means of an event.finger_id property.
An example can be found here:
https://www.patreon.com/posts/finger-painting-43786073?l=fr
You're going to have a difficult time if you insist on doing this in PyGame. Your best bet for multitouch in Python is Kivy, which was a very solid framework a few years ago when I used it and appears to have only gotten better since.
The disadvantage of switching to Kivy is a more complicated API, but this tutorial seems spot-on for what you're trying to do.
Related
The title explains it self basically, I want to draw for example a rectangle on a specific coordinate on the screen, using Python, how to achieve this?
I hear PyGame mentioned frequently, but I need a solution that would allow me to click through the shape, and as far as I understand you definitely need a Pygame window to draw anything on the screen and that would prevent clicking on whatever it is underneath, am I correct?
I am using a website called pixelpad.io to make my game, which is in Python. I am trying to make a simple platformer where the player can move horizontally and jump on blocks. Because of this website, I have to specify the co ordinates of each block for each level I make. Since this is all on a browser and I spawned all of the blocks in at the start of the game, the fps has been running slow. A friend of mine said to figure out the x co ordinate of left side of screen compared to the player along with the co ordinate of the right side. He then said to do some math to figure out which columns are visible, and generate the blocks in those columns. I somewhat understand his explanation but I am still confused on how to code it. How should I store and use all the block information for each column since the level is preset? I have a couple types of sprites for different blocks, so I'm not too sure how to store that information either. When the player is outside of a column that was rendered, does it destroy itself? I need an explanation for this, pseudo code, or an easier alternative to use.
I'm not sure what API you are using but I'm guessing it's not pygame. However, this pygame tutorial about optimization might help. I found the basic theory of it very useful in learning how to optimize my pygame game projects.
https://youtu.be/s3aYw54R5KY
I am trying to write a (board) game with cocos2d in python. I want to have a nice grass texture as background, and it should repeat itself when the Window is resized.
Currently I loaded sprite and just drew it multiple times in a batch, depending on the window size. Problem that i am encountering is that when the window is resized i have to redraw the background every time but I think that this is not the way to go.
For the C++ API of cocos2d, there is something like GL_REPEAT, but I did not find such thing for the python API. Is there something I have been missing, or do you know an easier approach?
Thanks in advance !
I am making a tile based game, and the map needs to be rendered every frame. Right now, each tile is 32X32, and the visible map is 28X28 tiles. The performance is dreadful. I recently made it only render the visible tiles, but this still did not improve the FPS much. Right now I'm looking for a way to speed up the rendering. I attribute the slowness to the way I am rendering ; every tile is individually blitted to the screen. What would be a more effective was of doing this?
In pygame (afaik), updating the screen is always one hell of a bottle neck. Since I could not see your code, I don't know, how you are updating the screen. Only blitting the the sprites that changed is a start, but you need to only update those parts that changed, on the screen.
Basically it is the difference between using display.flip() or using update_rects() with only the changed rects. I know, that does not help at all, when you are scrolling the map.
Take a look at this question: Why is this small (155 lines-long) Pacman game on Python running so slow?, it has a similiar topic.
One thing I tried when I had a map compiled of tiles and some sprites on it, I tried always having a precompiled image of the map for an area containing the currently displayed part and some 200 or so pixels around that, so that I could blit the prepared "ground" (still only in updated parts) without the need of blitting all those tiles contained in it. That, of course, is quite some thinking you have to put into that, espacially if you have multiple layers and parts of the map that can be above your active sprites. It is interesting to think and work that through, but I cannot tell you, how much you will gain by that.
One totally different possible solution: I began with pygame once (since I did SDL in C++ prior to that). Recently I was directed to another python gaming library: pyglet. This does not suffer from the problems of updating the whole screen as much as pygame (I think it's because of usage of OpenGL acceleration; it still works on my not at all accelerated eee-Netbook). If you are not bound to pygame in any way, it might be interesting to take a look at pyglet.
I want to automate playing a video game with Python. I want to write a script that can grab the screen image, diff it with the next frame and track an object to click on. What libraries would be useful for this other than PIL?
There are a few options here. The brute force diff'ing approach will lead to a lot of frustration unless what you're tracking is very consistent. For this you could use any number of genetic approaches to train your program what to follow. After enough generations it would do the right thing reliably. If the thing you want to track is visually obvious (like a red ball on a white screen) then you could detect it yourself through simple brute force scanning of the bitmap.
Another approach would be just looking at the memory of the running app, and figuring out what area is controlling the position of your object. For some more info and ideas on this, see how mumble got 3D positional audio working in various games.
http://mumble.sourceforge.net/HackPositionalAudio
Answer would depend on the platform and game too.
e.g. I did once similar things for helicopter flash game, as it was very simple 2d game with well defined colored maze
It was on widows with copy to clipboard and win32 key events using win32api bindings for python.