Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow assignment to Actor's width and height to scale the Actor #36

Open
lordmauve opened this issue Sep 18, 2015 · 12 comments
Open

Allow assignment to Actor's width and height to scale the Actor #36

lordmauve opened this issue Sep 18, 2015 · 12 comments
Labels
enhancement New feature or request minor

Comments

@lordmauve
Copy link
Owner

Originally reported by: Daniel Pope (Bitbucket: lordmauve, GitHub: lordmauve)


Assigning to height and width could cause the actor to be scaled.

This might scale around the 'pos' position.


@a96tudor
Copy link

Working on this.

a96tudor added a commit to a96tudor/pgzero that referenced this issue Jul 28, 2018
@aoloe
Copy link

aoloe commented Sep 18, 2018

yes, that's the biggest stepping stone i've encountered until now, while thinking about the migration path from scratch to pygame zero...

is any action (testing, ...) needed for this patch being added to the master?

@lordmauve
Copy link
Owner Author

When I last looked, the patch had some issues causing the pos point to move. I'll look again at this at the Pycon UK sprints tomorrow.

@aoloe
Copy link

aoloe commented Sep 18, 2018

thanks!

@aoloe
Copy link

aoloe commented Nov 4, 2018

any update?

@martindemello
Copy link
Contributor

setting width and height is slightly complicated because they refer to the bounding box of the image. i've added support for setting .dimensions in #185, which refers to the dimensions of the image before rotation, and scales it around the anchor point. is there still a use case for scaling a rotated image to an exact bounding box size?

@ZhangEPSB
Copy link

ZhangEPSB commented Jul 7, 2019

I submitted a pull request that may mitigate this issue. It doesn't let the user choose a pixel width and height, but it does allow them to scale the image (2x bigger/smaller). It may not be as specific, but it will prevent users from distorting the image when hard-coding width and height. Tested with colliderect and rotate. Hope it helps.

@aryoda
Copy link

aryoda commented Aug 15, 2019

Scaling the image would be great, eg. via using pygame.transform.scale():

def resize_actor(actor, new_width, new_heigth):
    # Resize and update the anchor point
    # See: https://www.pygame.org/docs/ref/transform.html#pygame.transform.scale
    actor._surf = pygame.transform.scale(actor._surf, (new_width, new_heigth))
    actor._update_pos()

@ZhangEPSB
Copy link

My pull request does use pygame.transform.scale(). It just uses factors of the current dimensions so that the image is not warped.

@aryoda
Copy link

aryoda commented Aug 16, 2019

Minimizing image distortion by allowing only whole-number factors is a good thing.

My use case is flexibility, eg. for maze-alike games like pacman where your images and actors must be resized to the same tile size of the "game grid".

If I have to use only images with the correct pixel size

  • I either have to edit each image if my images have the wrong image sizes
  • or I have to find new images

Furthermore games should support different screen resolutions and therefore scaling of the game window and the images.

Just my opinion, still pygame zero is of great use and I love using it :-)

@IsaacShelton
Copy link

Any updates? This issue has existed for 7 years now and there's still no way to scale an actor.

@IsaacShelton
Copy link

For anyone visiting this

The only way I was able to get it to work was by using the images object to load the image and then scale the result.

background = pygame.transform.scale(images.background, (WIDTH, HEIGHT))

So then I was able to blit the image itself onto the screen.

screen.blit(background, (0, 0))

Example

import pygame
import pgzrun

WIDTH = 600
HEIGHT = 600

background = pygame.transform.scale(images.background, (WIDTH, HEIGHT))

def draw():
    screen.blit(background, (0, 0))

pgzrun.go()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor
Projects
None yet
Development

No branches or pull requests

7 participants