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

#1 2012-08-25 06:41:17

liamx
Scratcher
Registered: 2012-06-15
Posts: 2

How move camera w/o dislocating sprites at edge?

liamx's daddy writing:

http://scratch.mit.edu/projects/liamx/2746199

When the camera moves everything to the edge, the internal position between the sprites is changed. How do I avoid this?

The sprites will (in the full script) move independently, ie the rabbit will move around without having the door follow so the distance between them cannot be fixed.

BTW, (and this might be a "too big" question), why is there an outer limit to how far a sprite can go off edge? Why must they bump into a

Thank you all!

smile

Offline

 

#2 2012-08-25 07:45:50

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: How move camera w/o dislocating sprites at edge?

Scratch, or some reason, doesn't allow less than 5px of a sprite to show up. The sprite will stay on the edge, ignoring any commands to go further.


http://i50.tinypic.com/312u714.jpg

Offline

 

#3 2012-08-25 13:16:34

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: How move camera w/o dislocating sprites at edge?

For some reason, as you've observed, sprites in Scratch can't move completely offscreen.  This is probably to prevent people from "losing" sprites.  However, it is a problem, especially when dealing with pen, since drawing off the side of the screen distorts the shape of the line. 

It would probably be a better idea to use "set position" blocks instead of "change position" blocks.  You can create a variable that holds the current scroll, or "camera" value, and a forever loop in both sprites that determines their positions based on that variable.  The arrow buttons would then adjust the variable, rather than the sprites' position.  For example:

This script goes in the right arrow sprite

when gf clicked
set [scrollX v] to [0]
forever
if <touching [mouse pointer v]?>
change [scrollX v] by [3]
end
end
... and this one goes in the left arrow sprite
when gf clicked
forever
if <touching [mouse pointer v]?>
change [scrollX v] by [-3]
end
end
And then put one of these in each of the moving sprites.  Replace "offset" with a value that represents how far the sprites should be offset from the "origin" at the beginning of the program.  Judging from what you have already, I'd guess you'd want to use an offset of 0 for the rabbit and -179 for the door. 
when gf clicked
forever
set x to ((scrollX) + [offset])
end
Hope that helps!

Last edited by amcerbu (2012-08-25 13:21:40)

Offline

 

#4 2012-08-25 15:18:59

liamx
Scratcher
Registered: 2012-06-15
Posts: 2

Re: How move camera w/o dislocating sprites at edge?

Thank you both so much for your informative answers! Amcerbu, your solution works perfectly. I would never have figured this out!!!

Regarding the "can't get quite off the edge" issue, I'm starting a new thread.

Again, thank you!

smile

Offline

 

#5 2012-08-25 18:30:30

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: How move camera w/o dislocating sprites at edge?

No problem, I enjoy helping people with scripts!  About the issue of the sprites not completely disappearing, you can create a "frame" sprite the size of the screen (480 x 360) with a black border around the edge, and with the interior of the sprite transparent (represented by the checkerboard pattern in the sprite editor).  I'm not sure exactly how thick the border should be it will have to be to hide the sprites, but 30 pixels will surely do the trick.  At the beginning of the program, this frame goes to the front of the screen.  It will hide the spots on the edge where sprites are "sticking out."

Offline

 

Board footer