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
Go
when gf clicked if <touching colour?> Broadcast ?vThen on the backround
when I receive ?v switch to backround?vHope I help!
Offline
Or, try this.
(Sprite)
when gf clicked forever if <touching color [#00FF00]?>//or any other color broadcast [touching v] stop script endOR
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)
Offline
Thats Sorta what I wrote trinary You just managed to do the (touching) script(s) Correctly
Offline
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.
Offline
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
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
i think forever if would make the background always set to 2 if touching other sprite.
i would always use
[scratchblocks]
forever
if
[/scractchblocks]
Offline
[forever] [if]does this one work?
Offline
I think, that anything serious.
Offline
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 endStage:
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:
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 endStage:
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)
Offline