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

#1 2012-07-21 22:34:08

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

Change background by touching a certain sprite?

I'm making a game where the player can walk around using the arrow keys, and I want them to be able to walk into buildings. So I want the background to change when they step in front of the door to enter the building

Offline

 

#2 2012-07-22 08:25:17

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: Change background by touching a certain sprite?

This script will also allow the player to exit the building.
For the player:

when gf clicked
forever
if <touching [door v]?>
if <(building)=[outside]>
set [building v] to [inside]
end
if <(building)=[inside]>
set [building v] to [outside]
For the Stage:
when gf clicked
forever
if <(building)=[outside]>
switch to background [outside v]
end
if <(building)=[inside]>
switch to background [inside v]
I hope that's clear.

Last edited by PhirripSyrrip (2012-07-22 08:27:17)


http://i46.tinypic.com/ao03lk.png

Offline

 

#3 2012-07-22 09:32:32

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Change background by touching a certain sprite?

PhirripSyrrip wrote:

This script will also allow the player to exit the building.
For the player:

when gf clicked
forever
if <touching [door v]?>
if <(building)=[outside]>
set [building v] to [inside]
end
if <(building)=[inside]>
set [building v] to [outside]
For the Stage:
when gf clicked
forever
switch to background (building)
I hope that's clear.

Simpler  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#4 2012-07-22 11:57:20

thebriculator
Scratcher
Registered: 2011-07-11
Posts: 500+

Re: Change background by touching a certain sprite?

Prestige wrote:

PhirripSyrrip wrote:

This script will also allow the player to exit the building.
For the player:

when gf clicked
forever if <touching [door v]?>
if <(building)=[outside]>
set [building v] to [inside]
else
set [building v] to [outside]
For the Stage:
when gf clicked
forever
switch to background (building)
I hope that's clear.

Simpler  smile

even more simple  big_smile

when it touches the door and the backround changes, be sure to make it go to the correct position.


.     http://tiny.cc/2cwgpw    http://tiny.cc/viwgpw    http://tiny.cc/iwwgpw

Offline

 

#5 2012-07-22 12:01:48

berberberber
Scratcher
Registered: 2012-03-08
Posts: 1000+

Re: Change background by touching a certain sprite?

thebriculator wrote:

Prestige wrote:

PhirripSyrrip wrote:

This script will also allow the player to exit the building.
For the player:

when gf clicked
forever if <touching [door v]?>
if <(building)=[0]>
set [building v] to [1]
else
set [building v] to [0]
For the Stage:
when gf clicked
forever
switch to background (building)
I hope that's clear.

Simpler  smile

even more simple  big_smile

when it touches the door and the backround changes, be sure to make it go to the correct position.

You guys are missing something:  The stage treats the reporter as a number, so even if you name your costume that, it doesn't matter.  Fixed.   smile


http://i47.tinypic.com/2iaa73k.png

Offline

 

#6 2012-07-22 12:11:36

PhirripSyrrip
Scratcher
Registered: 2012-02-11
Posts: 100+

Re: Change background by touching a certain sprite?

berberberber wrote:

thebriculator wrote:

Prestige wrote:


Simpler  smile

even more simple  big_smile

when it touches the door and the backround changes, be sure to make it go to the correct position.

You guys are missing something:  The stage treats the reporter as a number, so even if you name your costume that, it doesn't matter.  Fixed.   smile

For the purposes of the thread, and for simplicity and clarity in the project, I think mine will cause the least confusion.


http://i46.tinypic.com/ao03lk.png

Offline

 

#7 2012-07-22 22:11:07

thebriculator
Scratcher
Registered: 2011-07-11
Posts: 500+

Re: Change background by touching a certain sprite?

It WILL work it it's a word, I just tried it.

but with numbers, it could be even more simple:

when gf clicked
set [building v] to [0]
forever if <touching [door v]?>
set [building v] to ((1)-(building))

when gf clicked
forever
switch to costume (building)


.     http://tiny.cc/2cwgpw    http://tiny.cc/viwgpw    http://tiny.cc/iwwgpw

Offline

 

#8 2012-07-22 22:39:53

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

Re: Change background by touching a certain sprite?

thebriculator wrote:

It WILL work it it's a word, I just tried it.

but with numbers, it could be even more simple:

when gf clicked
set [building v] to [0]
forever if <touching [door v]?>
set [building v] to ((1)-(building))

when gf clicked
forever
switch to costume (building)

Costume numbering in scratch begins at 1, so, though your script could be applied, it is counter intuitive, so you should set "building" to 1 originally and replace "1-building" with "(3)-(building)"

The (potential) problem with all the scripts above is that, if you're touching the door for too long.  If this is a problem, use this:

when gf clicked
set [buildiing v] to [1]
forever if <touching [door v]?>
set [building v] to ((3)-(building))
wait until <not<touching [door v]?>>

when gf clicked
forever
switch to costume (building)
Of course, if there are only two costumes, it is even easier:

when gf clicked
forever if <touching [door v]?>
broadcast [change v]
wait until <not<touching [door v]?>>

When I Receive [change v]
next costume


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

Offline

 

#9 2012-07-23 12:14:09

WoopAhhh
New Scratcher
Registered: 2012-07-19
Posts: 19

Re: Change background by touching a certain sprite?

thebriculator wrote:

Prestige wrote:

PhirripSyrrip wrote:

This script will also allow the player to exit the building.
For the player:

when gf clicked
forever if <touching [door v]?>
if <(building)=[outside]>
set [building v] to [inside]
else
set [building v] to [outside]
For the Stage:
when gf clicked
forever
switch to background (building)
I hope that's clear.

Simpler  smile

even more simple  big_smile

when it touches the door and the backround changes, be sure to make it go to the correct position.

Can you maybe make this and upload it? I don't understand

Offline

 

#10 2012-07-23 12:30:34

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

Re: Change background by touching a certain sprite?

We've been assuming that you're storing the interior of the building as a costume in the background, and that the door itself is a sprite.  Basically, whenever the user touches the door it changes the costume that the background is currently in.  A more universal script (just realized you probably have more than one building) would be this:

when gf clicked
forever
whatever your current movement script is
if<touching [door1 v]?>
broadcast [enter building 1 v] and wait
go to x:(starting x position for building 1) y:(starting y position for building 1)
end
if<touching [door2 v]?>
broadcast [enter building 2 v] and wait
go to x:(starting x position for building 2) y:(starting y position for building 2)
end
etc.
And for the stage:

when I receive [enter building 1 v]
switch to costume [building 1 v]

when I receive [enter building 2 v]
switch to costume [building 2 v]


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

Offline

 

Board footer