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

#1 2012-04-29 12:33:10

Tweetwolf
New Scratcher
Registered: 2012-04-29
Posts: 1

how to make backround change when you go ast edge

im relly stuck on this! i know its probably really easy but help would be much appreciated
thanx very much  big_smile

Offline

 

#2 2012-04-29 13:05:11

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make backround change when you go ast edge

If you wanted a scroller, just use the wiki:http://wiki.scratch.mit.edu/wiki/Scrolling
If you want a normal movement with background changes then you use this script:

when gf clicked //player sprite
forever
if (x position) < [245]
broadcast [right v]
end
if (x position > [-245] // these values may need tuning
broadcast [left v]
end

when gf clicked // put this in the stage
delete [all v] of [rightlist v]
delete [all v] of [leftlist v]
set (backgroundcounter) to 0
set (leftcounter) to 0
set (rightcounter) to 0
add (rightbackground1) to [rightlist v]
add (rightbackground2) to [rightlist v] // as many backgrounds to the right as you have
add (leftbackground1) to [leftlist v]
add (leftbackground2) to [leftlist v] // as many backgrounds to the left as you have

when I receive [right v]
change [backgroundcounter v] by [1]
change [rightcounter v] by [1]
change [leftcounter v] by [-1]
if (backgroundcounter) < 1
switch to background item (leftcounter) of [leftlist v]
else
switch to background item (rightcounter) of [rightlist v]

when I receive [left v]
change [backgroundcounter v] by [-1]
change [rightcounter v] by [-1]
change [leftcounter v] by [1]
if (backgroundcounter) < 1
switch to background item (leftcounter) of [leftlist v]
else
switch to background item (rightcounter) of [rightlist v]
I have NO idea if this'll work, I came up with it on the spot but it should work. Code order might need a bit of tweaking


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#3 2012-04-29 13:09:12

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make backround change when you go ast edge

zammer990 wrote:

EDIT
mostly fixed scratch blocks

when gf clicked //player sprite
forever
   if (x position) < [245]
   broadcast [right v]
   if (x position) > [-245] // these values may need tuning
   broadcast [left v]
end

when gf clicked // put this in the stage
delete [all v] of [rightlist v]
delete [all v] of [leftlist v]
set (backgroundcounter) to 0
set (leftcounter) to 0
set (rightcounter) to 0
add (rightbackground1) to [rightlist v]
add (rightbackground2) to [rightlist v] // as many backgrounds to the right as you have
add (leftbackground1) to [leftlist v]
add (leftbackground2) to [leftlist v] // as many backgrounds to the left as you have

when I receive [right v]
change [backgroundcounter v] by [1]
change [rightcounter v] by [1]
change [leftcounter v] by [-1]
if (backgroundcounter) < [1]
switch to background item (leftcounter) of [leftlist v]
else
switch to background item (rightcounter) of [rightlist v]

when I receive [left v]
change [backgroundcounter v] by [-1]
change [rightcounter v] by [-1]
change [leftcounter v] by [1]
if (backgroundcounter) < [1]
switch to background item (leftcounter) of [leftlist v]
else
switch to background item (rightcounter) of [rightlist v]
I have NO idea if this'll work, I came up with it on the spot but it should work. Code order might need a bit of tweaking


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#4 2012-04-29 13:16:05

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: how to make backround change when you go ast edge

Wow zammer990, i don't think it needs to be that complicated!

if <<<(x position) > [240]> or <(x position) < [-240]>> or <<(y position) > [180]> or <(y position) < [-180]>>>
broadcast [change background v]
end

when i receive [change background v] //in the Stage
switch to background [other background v]

Offline

 

#5 2012-05-02 07:55:25

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make backround change when you go ast edge

scimonster wrote:

Wow zammer990, i don't think it needs to be that complicated!

if <<<(x position) > [240]> or <(x position) < [-240]>> or <<(y position) > [180]> or <(y position) < [-180]>>>
broadcast [change background v]
end

when i receive [change background v] //in the Stage
switch to background [other background v]

My way was a bit of a bizzare way of doing it I know  big_smile

Your way would only work assuming you only wanted to have it change backgrounds in one long line, for example if you went left right left right left you would just change to background 2,3,4,5,6

My code makes it multidirectional, going left then right would take you back to costume 1


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#6 2012-05-02 11:20:10

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: how to make backround change when you go ast edge

Or how about this:

forever
if<touching [edge v]?>
broadcast [change background v]
wait until <not <touching [edge v]?>> // optional
end

Last edited by MoreGamesNow (2012-05-02 11:20:59)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#7 2012-05-02 11:53:44

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: how to make backround change when you go ast edge

^Again that would only work for one directional, or more specifically it'd just be an iterating sequence of backgrounds


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer