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

#1 2007-06-02 02:52:32

mohlar
Scratcher
Registered: 2007-05-24
Posts: 100+

How to trigger a new background when sprite reaches edge

I know there's a 'change background' control, but how can it be used so that when a character sprite reaches a specific position (say x>240 for the same of argument) the background changes to the next one in a sequence?

Offline

 

#2 2007-06-02 03:18:51

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How to trigger a new background when sprite reaches edge

Have the sprite broadcast a "next background" message and have the stage use "when I receive next background"

Offline

 

#3 2007-06-02 03:56:32

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: How to trigger a new background when sprite reaches edge

Or, have the sprite constant set a pair of global variables to its x and y positions.

Then the stage can have a script that checks these variables and changes the background when required.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#4 2007-06-02 18:46:12

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: How to trigger a new background when sprite reaches edge

Mayhem's method will work, and I have used things like it, but it is usually cleaner to have sprites detect things about themselves and broadcast messages to let other sprites (and the stage) know when things have happened.  Relying on other sprites detecting things often runs into timing problems.

Offline

 

Board footer