gg.wilson

How to keep position of sprite after being scaled(mine keeps moving to left corner)

Recommended Posts

Hey everyone hopefully this is worded ok and you are having a good day.

I currently have a playable character which can be moved around and collide with objects.

The issue i am having is once it has collided with a certain object i want the players character sprite to increase in size however when i do this using sprite.scale.setTo for some reason the position of the player sprite moves to 0,0. 

Apologise if that was not enough information i can provide more if needed.

Share this post


Link to post
Share on other sites

Hello!

You can try setting the scale as below:

sprite.scale.x = 1.5; // Increases the X scale by 1.5x times.
sprite.scale.y = 2; // Increases the X scale by 2x times.

A similar use of this example is to "invert/mirror" the sprite, you just have to set the scale to -1.

Share this post


Link to post
Share on other sites
19 hours ago, gg.wilson said:

The issue i am having is once it has collided with a certain object i want the players character sprite to increase in size however when i do this using sprite.scale.setTo for some reason the position of the player sprite moves to 0,0. 

If a sprite changes size (instantly), it can cause new collisions that move the sprite. But the scale change itself doesn't affect position.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.