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

#1 2007-05-24 14:52:15

seijo
Scratcher
Registered: 2007-05-24
Posts: 5

Touching Edge Logic?

I've noticed that "touching edge" is often True when the sprite image is not actually touching the edge.  The larger the image, the greater the whitespace between the image and the sprite seems to be.  What's going on here?

This is easily demonstrated with a large circle-shaped sprite.  Sprites in the shape of perfect rectangles don't seem to have this problem.

Offline

 

#2 2007-05-24 15:00:40

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Touching Edge Logic?

I'm not seeing this behavior. Could your sprite costume have pixels that match the stage color around the visible shape? If you go in to the sprite editor you should see the grey and white checkerboard pattern coming right up to the edge of your sprite. If you don't, you can erase the extra pixels.

Offline

 

#3 2007-05-24 15:13:38

seijo
Scratcher
Registered: 2007-05-24
Posts: 5

Re: Touching Edge Logic?

Clarification to my original post:

This distance from the edge at which "touching" occurs depends on the heading.  At 0 degrees or 90 degrees, there is no white space between a circular sprite and the edge.  At 45 degrees, there is signifcant white space.

SO, I think I answered my own question.  Picture an imaginary rectangle drawn around and enclosing the sprite, whatever it's shape may be.  "Touching" then occurs when that rectangle touches the edge.  (I tested this by actually drawing a rectangle around the sprite in the edit window using the rectangle tool.)

Have I got it right?  Anything to add?  Is all of this explained somewhere in the reference material that I missed?

Offline

 

#4 2007-05-24 15:26:50

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Touching Edge Logic?

Ouch, you're right. But it's not as if you can draw the smallest possible imaginary rectangle to predict where it will stop, it seems to just come up pretty far short. I'm fairly certain that this is a bug. It happens in the Java applet and in the Scratch application.

Offline

 

#5 2007-06-01 10:52:30

seijo
Scratcher
Registered: 2007-05-24
Posts: 5

Re: Touching Edge Logic?

It seems to me that a tight rectangle drawn around the sprite using the rectangle tool in the costume editor pretty accurately describes where the"touching" will occur.

By the way, I saw the term "bounding box" used in the first reply to post #403 by kevin karplus and wonder if this is the concept at play here.  Am I on the right track?

And I'll re-pose my original question: Is all of this explained somewhere in the reference material?  Or can you point me to some relevant explanatory material?

Thanks

Joe Delfausse

Offline

 

#6 2007-06-01 11:05:47

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Touching Edge Logic?

As a work-around, you could try something like

If touching edge
- (set "variable" to direction)
- Set direction to 0
- If touching edge (do whatever it is you wanted it to do)
-----else set direction to "variable"


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#7 2007-06-01 11:17:49

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Touching Edge Logic?

That workaround might work, but it could be visually undesirable if the sprite is set to rotate.

Joe, I don't think you're going to find it explained anywhere because I'm pretty sure it's a bug. I suggest that you post it in the troubleshooting forum to bring it to the attention of the Scratch team.

Offline

 

#8 2007-06-01 16:21:55

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Touching Edge Logic?

OK, a new discovery. I tried putting a box around the sprite and that illuminated the problem. I expected the box to fit nicely into the corner but when the sprite rotated to a 45 deg. angle the box did indeed touch the edge before the circle inside it.

Then I tried something else. I went back to a large circle, but this time I set the sprite to not rotate at all. That fixed the problem and the circle goes all the way to the edge before triggering the touching edge. So that's a good work around for when you don't need the sprite to rotate anyway.

That said, I still think it's a bug. The touching edge is clearly being calculated based on an imaginary bounding box rather than actual pixels of the sprite itself.

I did one last test to see if this affected the sensing of a sprite touching another sprite and it does not. Two sprites are only considered to be touching if their pixels are actually touching each other.

Offline

 

#9 2007-06-01 17:27:14

seijo
Scratcher
Registered: 2007-05-24
Posts: 5

Re: Touching Edge Logic?

jd, I like your workaround.  Most of the time it's a round ball we're having the problem with.

Thanks also for testing the sprite touching another sprite.  That's something I've been planning to test but never got to.  And it's good news that this works, because you often have the situation when a moving ball touches a paddle, as in ping pong.

Thanks - Joe

Offline

 

Board footer