This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-10-08 12:11:39

forrie
Scratcher
Registered: 2007-09-30
Posts: 4

How to determine if Sprite is near 0,0 (x,y) ?

I'm trying to find a clever way to determine (sense) if the Sprite one pixel near 0,0 (negative direction included).  I've been trying abs() and such, but cannot seem to figure it out.

When my Sprite hits 1 pixel near 0,0, I want it to perform a function (that's the easy part).

I would think that something like that would be an appropriate Sense function (with tunable variables).


Thanks.

Offline

 

#2 2007-10-08 12:21:40

EdnaC
Scratcher
Registered: 2007-08-28
Posts: 100+

Re: How to determine if Sprite is near 0,0 (x,y) ?

Checking the absolute value of the sprite's X and Y will do the trick, so you're on the right track.  The statement can be:

If (ABS (X) < (some number)) AND (ABS (Y) < (some number))

- Take some action

Where X and Y are the Sprite's coordinates and "some number" is whatever threshold amount you choose to call "close enough" to zero.

Offline

 

#3 2007-10-08 12:27:02

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: How to determine if Sprite is near 0,0 (x,y) ?

There's many ways to do it.  EdnaC has good one.  You can also do these

if ( ( abs( x ) + abs( y ) ) < (small number) )

or

if ( ( x * x + y * y ) < (small number ) )

Offline

 

#4 2007-10-08 12:43:50

forrie
Scratcher
Registered: 2007-09-30
Posts: 4

Re: How to determine if Sprite is near 0,0 (x,y) ?

Thank you very much.  I used EndaC's suggestion -- I'm not that clever in math, which is probably why I had a difficult time grasping this.  But you learn as you go ;-)

Offline

 

Board footer