Discuss Scratch

scratch0maker0
Scratcher
100+ posts

How to find out width/height of something

How do you find out the width/height of something? I need it for a pixel-ized game.
deck26
Scratcher
1000+ posts

How to find out width/height of something

If it's a costume the size is shown under the costume in the editor. If it's part of a costume it might be worth copying the costume and deleting the other bits to use the same method.
footsocktoe
Scratcher
1000+ posts

How to find out width/height of something

scratch0maker0 wrote:

How do you find out the width/height of something? I need it for a pixel-ized game.

You might be able to figure out a way using “touching” sensor. Move thing you want to measure across a touching sensor while counting pixels moved and save when it first touches and when it last touches. That should give you the width.
deck26
Scratcher
1000+ posts

How to find out width/height of something

https://scratch.mit.edu/projects/58335070/ is an old project of mine.
learncsscratch
Scratcher
100+ posts

How to find out width/height of something

put down two sprites on the screen and then use the
(distance to [ v])
block to give you the distance between the two sprites
footsocktoe
Scratcher
1000+ posts

How to find out width/height of something

learncsscratch wrote:

put down two sprites on the screen and then use the
(distance to [ v])
block to give you the distance between the two sprites

Except that wasn't the question asked. The question is what is the width of a sprite.
asivi
Scratcher
1000+ posts

How to find out width/height of something

Well, @scratch0maker0 must explain if they wants to know H&W in the painter or how it looks in the flashplayer screen, in the second case it would be because a percentage resize so they could use maths.
TheLogFather
Scratcher
1000+ posts

How to find out width/height of something

Griffpatch found a really neat way to get a costume's bounding-box by using the limits that Scratch itself places on a sprite's position.

The basic idea is that if you just move the sprite to a huge x & y position, and then do the same with huge negative x & y position, then you can work out the dimensions by looking at the x/y position that Scratch actually gave the sprite in the two cases.

The reason it works is because Scratch always forces a sprite to have 15 pixels of the width/height of a costume left on screen.

The project is here: https://scratch.mit.edu/projects/110878444/

It's much more efficient than any other method given here, since it only needs *two* moves.

And you can even use it to work out how the sprite is centred!

Last edited by TheLogFather (March 22, 2017 18:01:56)

learncsscratch
Scratcher
100+ posts

How to find out width/height of something

In game, you can place a sprite so it is touching the left, and another sprite that is touching the right, and then read the distance between the two sprites….(placing the two sprites can be done many different ways, it does not even have to be just left and right, it can be any dimension of the sprite to be measured)…this is a run-time solution (much like what you suggested) rather than a build-time solution of looking in the costume editor…

I was just pointing out an internal function that could help to find the answer… My apologies if the solution was not obvious, but yes, it is an answer to the question asked.

Examples:

place one sprite at x-position -240 and have it move until touching the sprite to be measured and a second sprite at 240 moving in the opposite direction until it touches the sprite…then the distance function will give you the answer…

move both sprites to the sprite to be measured and move one left and the other right until not touching the sprite,,,then get the answer from the distance block…

You can use either of these solutions to measure top to bottom or even arbitrary angles…

The point is, Scratch has a built in distance function that can be leveraged if you desire…


Happy Scratching!!!
footsocktoe
Scratcher
1000+ posts

How to find out width/height of something

learncsscratch wrote:

In game, you can place a sprite so it is touching the left, and another sprite that is touching the right, and then read the distance between the two sprites….(placing the two sprites can be done many different ways, it does not even have to be just left and right, it can be any dimension of the sprite to be measured)…this is a run-time solution (much like what you suggested) rather than a build-time solution of looking in the costume editor…

I was just pointing out an internal function that could help to find the answer… My apologies if the solution was not obvious, but yes, it is an answer to the question asked.

Examples:

place one sprite at x-position -240 and have it move until touching the sprite to be measured and a second sprite at 240 moving in the opposite direction until it touches the sprite…then the distance function will give you the answer…

move both sprites to the sprite to be measured and move one left and the other right until not touching the sprite,,,then get the answer from the distance block…

You can use either of these solutions to measure top to bottom or even arbitrary angles…

The point is, Scratch has a built in distance function that can be leveraged if you desire…


Happy Scratching!!!

Thanks for the clarify. I understand now!

Powered by DjangoBB