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

#1 2012-05-17 03:22:38

TillyVanilly
New Scratcher
Registered: 2012-05-17
Posts: 1

Changing backgrounds

How can I make the change of background dependant on what the sprites are doing?  How do I change the background when two sprites touch?

Offline

 

#2 2012-05-17 04:32:07

Jem12
Scratcher
Registered: 2012-04-20
Posts: 100+

Re: Changing backgrounds

Go

when gf clicked
if <touching colour?>
Broadcast ?v
Then on the backround
when I receive ?v
switch to backround?v
Hope I help!  tongue

CLICK HERE!


"In the begging the universe was created, this made a lot of people angry and was widly regarded as a bad move" ~  Douglas Adams ~ The resturant at the end of the universe

Offline

 

#3 2012-05-17 05:42:50

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: Changing backgrounds

Or, try this.


(Sprite)

when gf clicked
forever if <touching color [#00FF00]?>//or any other color
broadcast [touching v]
stop script
end
OR

when gf clicked
forever if <touching [sprite2 v]?>//or any other sprite
broadcast [touching v]
stop script
end
(Background)
when gf clicked
switch to background [background1 v]
when I receive [touching v]
switch to background [background2 v]

Last edited by trinary (2012-05-18 02:10:57)


http://trinary.tk/images/signature_.php

Offline

 

#4 2012-05-17 08:01:30

Jem12
Scratcher
Registered: 2012-04-20
Posts: 100+

Re: Changing backgrounds

Thats Sorta what I wrote trinary  smile  You just managed to do the (touching) script(s) Correctly


"In the begging the universe was created, this made a lot of people angry and was widly regarded as a bad move" ~  Douglas Adams ~ The resturant at the end of the universe

Offline

 

#5 2012-05-17 10:35:03

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: Changing backgrounds

Your scripting was sound trinary, but using sprite instead of color sensing normally works best. The following would show you that you can see if it is touching the other sprite and not the color, this helps if you want something else that color, then you don't have to worry. If you only want this to happen when a certain part is being touched, then you would use color, otherwise, this should work best.

when gf clicked
if <touching [sprite 2 v]?>
broadcast [background2 v]
You will also need the script for the stage from trinary's post to make this work.


Why are the secret organizations getting all the attention?  mad

Offline

 

#6 2012-05-19 10:51:17

AliensFTW
New Scratcher
Registered: 2012-05-01
Posts: 19

Re: Changing backgrounds

If you want a smoother action I would use variables.
[scratchblocks]
when gf clicked
forever
    switch to background [backroundnumber]   //insert the variable block there.
end



when gf clicked
forever if <touching [othersprite v]>
    Set backroundnumber to (2) //this will make you switch to backround two.
end

Offline

 

#7 2012-05-19 10:54:36

AliensFTW
New Scratcher
Registered: 2012-05-01
Posts: 19

Re: Changing backgrounds

Sorry here it is in blocks

AliensFTW wrote:

If you want a smoother action I would use variables.

when gf clicked
forever
    switch to background [backroundnumber]   //insert the variable block there.
end



when gf clicked
forever if <touching [othersprite v]>
    Set backroundnumber to (2) //this will make you switch to backround two.
end

Offline

 

#8 2012-05-19 11:21:12

backspace_
Scratcher
Registered: 2012-03-21
Posts: 500+

Re: Changing backgrounds

i think forever if would make the background always set to 2 if touching other sprite.
i would always use
[scratchblocks]
forever
if
[/scractchblocks]


Your tiny hands
Your crazy kitten smile

Offline

 

#9 2012-05-19 11:31:17

backspace_
Scratcher
Registered: 2012-03-21
Posts: 500+

Re: Changing backgrounds

[forever]
[if]
does this one work?


Your tiny hands
Your crazy kitten smile

Offline

 

#10 2012-05-21 06:15:40

TeadsTetRam
New Scratcher
Registered: 2012-05-21
Posts: 23

Re: Changing backgrounds

I think, that anything serious.

Offline

 

#11 2012-05-21 07:21:15

SciTecCf
Scratcher
Registered: 2011-11-23
Posts: 1000+

Re: Changing backgrounds

EXAMPLE:

Let's say you have a project with 3 sprites, and the background has 3 costumes. Let's say you want it so that if Sprite1 is touching Sprite2, the stage needs to switch to background2. If Sprite1 is touching Sprite3, the stage needs to switch to background3. If Sprite1 is not touching Sprite2 or Sprite3, the stage needs to switch to background1. To achieve this, you would use these scripts:

Sprite1:

when gf clicked
forever
  if <touching [Sprite2 v]?>
    broadcast [bg2 v]
    wait until <not <touching [Sprite2 v]?>>
  else
    if <touching [Sprite3 v]?>
      broadcast [bg3 v]
      wait until <not <touching [Sprite3 v]?>>
    else
      broadcast [bg1 v]
      wait until <<touching [Sprite2 v]?> or <touching [Sprite3 v]?>>
    end
  end
end
Stage:

when gf clicked
switch to costume [background1 v]
when I receive [bg1 v]
switch to background [background1 v]
when I receive [bg2 v]
switch to background [background2 v]
when I receive [bg3 v]
switch to background [background3 v]
Or, if you like, you can use variables:

Sprite1:

when gf clicked
forever
  if <touching [Sprite2 v]?>
    set [bg v] to [2]
    wait until <not <touching [Sprite2 v]?>>
  else
    if <touching [Sprite3 v]?>
      set [bg v] to [3]
      wait until <not <touching [Sprite3 v]?>>
    else
      set [bg v] to [1]
      wait until <<touching [Sprite2 v]?> or <touching [Sprite3 v]?>>
    end
  end
end
Stage:
when gf clicked
set [bg v] to [1]
forever
  if <(bg) = [2]>
    switch to background [background2 v]
    wait until <not <(bg) = [2]>>
  else
    if <(bg) = [3]>
      switch to background [background3 v]
      wait until <not <(bg) = [3]>>
    else
      switch to background [background1 v]
      wait until <not <(bg) = [1]>>
    end
  end
end

Last edited by SciTecCf (2012-05-21 15:03:30)


http://bit.ly/LCZEJRhttp://bit.ly/LSONcOhttp://bit.ly/LF3vIc
http://trinary.site40.net/images/scratchrank.php?username=SciTecCf&amp;display=small

Offline

 

Board footer