I'm trying to put a picture in my python game, so far I have this:
picture = pygame.image.load(picture.jpg)
screen.fill(BLACK)
screen.blit(picture, (0,0))
This successfully adds the picture, but takes up the whole screen. Is it possible to reduce the size of this picture?
Thank you for the help.
It looks like you can scale an image with transform.scale.
picture = pygame.transform.scale(picture, (1280, 720))
Also have you tried playing around with the parameters in screen.blit?
I think instead of passing a point into the "Dest" parameter you can pass a rectangle.
screen.blit(picture), (0,0,width,height))
Related
So I've been struggling with this for a lot of time, I'll keep it short.
I'm working on my first P5JS game, and it's like Mario, but instead of horizontal endless runner, its vertical. So, I added an image as the background like this in setup function:
bg=createSprite(300,300);
and in the draw function:
background("black");
bg.addImage(bgImage);
bg.velocityY=5;
The velocityY constantly makes the image move downwards, but because it is an image, after a while the black background comes up again.
Like so:(the road is the image and the black color is the background.)
So how do I make it so that after the image has gone away, it comes back in, and it seems like it never even left?
Well, you could have two images, whenever one is fully invisible (img.y < height)
just teleport it back up to the top img.y = img2.y - img.height.
Also i believe that's the math to do so, but i'm not completely sure about it.
Also there might be a function for tiling in the library.
Is there a way to let the player save a high-resolution image of the game, while still maintaining all effects? For example, I have glow filters set to 2px. When I use the regular drawBitmap, everything is pixellated and the filters don't look great. So I've started enlarging the movieclip to double the size, then creating a bitmap that's twice the size and saving that. But the problem is that the filter effects get scaled down. For example, if the image went from 400 to 800 px tall, the 2px filter effect now looks half the size and warps everything.
I know this must be possible because, for example, using a fullscreen function does this already... it enlarges everything to a beautiful high resolution, while maintaining all effects relative to each other. How can I capture this effect in an image-saving capacity? (currently using jpegencoder)
Sounds like you have some aliasing so you'll need a re-sampling (blend) function to fix those jagged edges.
A good one is : Lanczos Resampler by Jozef Chúťka.
The important part from that demo code is the LanczosBitmapDataResizer class code about halfway scrolling down the page.
import flash.display.BitmapData;
import flash.utils.Dictionary;
class LanczosBitmapDataResizer
{ ...etc etc...
and it's accessed by updating a BitmapData
new_smooth_BMD = LanczosBitmapDataResizer.resize( old_pixelated_BMD, 227, 227 );
I've tried a bunch of alternatives, and but each approach has not produced the desired result of stretching an image from a new sx to the end of the canvas.
I'm going to assume the image shows what you want to happen, not what is actually happening. You can do all of this in the drawImage call. You don't typically see the parameters explained this way, but I think it will help for what you want to do.
ctx.drawImage(imgSrc, cropX, cropY, cropWidth, cropHeight, drawAtX, drawAtY, drawWidth, drawHeight);
https://jsfiddle.net/yLf5erut/2/
Im trying to get something like this --> http://jsfiddle.net/NhvAZ/10/ but with image inside circle.
I did exactly the same way like on example above, but it doesn't work with image. Here is my code: http://jsfiddle.net/uyEaq/
Someone could tell me what I'm doing wrong?
Well that was really confusing, but looking at some of the previous iterations of the fiddles you've given I think I know what you want.
You want an ever increasing pie slice of an image to appear, right? Clipping can do that for you. Here's an example using some of your code:
http://jsfiddle.net/QMZg2/
So I know how to shade an image. And I know how to blit a rectangular section of an image. But what about, say, a triangle? Or a trapezoid? (e.g. http://i.imgur.com/Gtwhs.png)
A minute after I asked this, I figured out how to shade, at least. Isn't that always the way?
Anyway, it basically comes down to something as simple as:
surface.blit(image, pos, area)
pygame.draw.polygon(surface, (0,0,0,128), pointlist, 0)
where 128 is whatever alpha value you want and pointlist is a list of the vertices around the section you want.