Discuss Scratch

kbrakkee
Scratcher
11 posts

How do I get 'original' x y postion of off centered sprite

I have a sprite that is not located in the center (so the cross does not hit the center cross in the costume view).
How can I get the position of it?

To illustrate I have made this:
https://scratch.mit.edu/projects/997821579/

As you can see both sprites have coordinates x:0 and Y:0 while sprite2 is actually on a different location
MineTurte
Scratcher
1000+ posts

How do I get 'original' x y postion of off centered sprite

kbrakkee wrote:

I have a sprite that is not located in the center (so the cross does not hit the center cross in the costume view).
How can I get the position of it?

To illustrate I have made this:
https://scratch.mit.edu/projects/997821579/

As you can see both sprites have coordinates x:0 and Y:0 while sprite2 is actually on a different location
If the sprite isn't centered in the costume editor it won't appear to be in the same location. If that is what you mean.
kbrakkee
Scratcher
11 posts

How do I get 'original' x y postion of off centered sprite

MineTurte wrote:

kbrakkee wrote:

I have a sprite that is not located in the center (so the cross does not hit the center cross in the costume view).
How can I get the position of it?

To illustrate I have made this:
https://scratch.mit.edu/projects/997821579/

As you can see both sprites have coordinates x:0 and Y:0 while sprite2 is actually on a different location
If the sprite isn't centered in the costume editor it won't appear to be in the same location. If that is what you mean.

@MineTurtle, No that is not what I mean. I want to know the exact location of Sprite2 to its center, in other words: how should I alter it's x- and y-position to get it on exact the same location as sprite1
The_wolf_KA
Scratcher
100+ posts

How do I get 'original' x y postion of off centered sprite

You could manually put in inputs until the sprite becomes centered.
It might take awhile though-

Also, why do you intend to make the sprite off center?
happyha8
Scratcher
500+ posts

How do I get 'original' x y postion of off centered sprite

Just make them be in the same place and center them on the cross
SpyCoderTest
Scratcher
57 posts

How do I get 'original' x y postion of off centered sprite

kbrakkee wrote:

MineTurte wrote:

kbrakkee wrote:

I have a sprite that is not located in the center (so the cross does not hit the center cross in the costume view).
How can I get the position of it?

To illustrate I have made this:
https://scratch.mit.edu/projects/997821579/

As you can see both sprites have coordinates x:0 and Y:0 while sprite2 is actually on a different location
If the sprite isn't centered in the costume editor it won't appear to be in the same location. If that is what you mean.

@MineTurtle, No that is not what I mean. I want to know the exact location of Sprite2 to its center, in other words: how should I alter it's x- and y-position to get it on exact the same location as sprite1
I don't get what you mean.

Both sprite are at 0,0… they are already on the same spot.

Do you want the positions to line up? Or the costumes?
kbrakkee
Scratcher
11 posts

How do I get 'original' x y postion of off centered sprite

SpyCoderTest wrote:

Both sprite are at 0,0… they are already on the same spot.

Do you want the positions to line up? Or the costumes?

Please click https://scratch.mit.edu/projects/997821579/
and you can see they are not on the same location (because of the different center).

What should the position of sprite2 be to get them on exactly the same spot.
Norse7
Scratcher
100+ posts

How do I get 'original' x y postion of off centered sprite

You could try this script on Sprite2 to center it:

define Center
go to x (-9999) y (0)
repeat until <not <touching [edge v] ?>>
change x by (1)
end
set y to (-9999)
repeat until <not <touching [edge v] ?>>
change y by (1)
end
change x by (240)
change y by (180)

Make the Center custom block Run Without Screen Refresh.
I got it from this tutorial by @griffpatch.
ItBeJC
Scratcher
1000+ posts

How do I get 'original' x y postion of off centered sprite

-Redacted
Dang I really thought that was gonna work, but it won't after further consideration.

Last edited by ItBeJC (April 10, 2024 02:03:50)

Norse7
Scratcher
100+ posts

How do I get 'original' x y postion of off centered sprite

ItBeJC wrote:

-Redacted
Dang I really thought that was gonna work, but it won't after further consideration.
Yeah, I'm not quite sure how to make the X position not interfere with the X in that script because I'm using
<touching [edge v] ?>
.

SpyCoderX
Scratcher
1000+ posts

How do I get 'original' x y postion of off centered sprite

Norse7 wrote:

You could try this script on Sprite2 to center it:

define Center
go to x (-9999) y (0)
repeat until <not <touching [edge v] ?>>
change x by (1)
end
set y to (-9999)
repeat until <not <touching [edge v] ?>>
change y by (1)
end
change x by (240)
change y by (180)

Make the Center custom block Run Without Screen Refresh.
I got it from this tutorial by @griffpatch.
Slight modifications should make this work (untested though):
define Center
go to x ((-1)/(0)) y (0)
repeat until <not <touching [edge v] ?>>
change x by (1)
end
set y to ((-1)/(0))
repeat until <not <touching [edge v] ?>>
change y by (1)
end
change x by (240)
change y by (180)
set [x1 v] to (x position)
set [y1 v] to (y position)
go to x ((1)/(0)) y (0)
repeat until <not <touching [edge v] ?>>
change x by (-1)
end
set y to ((1)/(0))
repeat until <not <touching [edge v] ?>>
change y by (-1)
end
change x by (240)
change y by (180)
go to x: (((x1)+(x position))/(2)) y: (((y1)+(y position))/(2))

Hope this helps!

Powered by DjangoBB