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

#1 2012-07-11 04:29:03

Deathray957
New Scratcher
Registered: 2012-06-15
Posts: 2

Have sprites swap positions with each other

I have two sprites when either one of them has been clicked they change their costume and display an outline around them representing that they have been selected. I want them to simultaneously swap their positions with each other when they have both been selected.

Offline

 

#2 2012-07-11 05:36:20

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

Re: Have sprites swap positions with each other

Try this:

For the first one:

when gf clicked
switch to costume [notselected v] //Your first costume,  where the sprite isn't selected.
when [Sprite1] clicked
next costume
if <<([costume # v] of [Sprite2 v]) = [2]> and <(costume #) = [2]>>
 broadcast [move_1and2 v]
end
when i receive [move_1and2 v]
set [gox v] to ([x position v] of [Sprite2 v])
set [goy v] to ([y position v] of [Sprite2 v])
broadcast [2go v] and wait
go to x: (gox) y: (goy)
Second one:

when gf clicked
switch to costume [notselected v] //Your first costume,  where the sprite isn't selected.
when [Sprite2] clicked
next costume
if <<([costume # v] of [Sprite1 v]) = [2]> and <(costume #) = [2]>>
 broadcast [move_1and2 v]
end
when i receive [2go v]
go to [Sprite1 v]

Last edited by SciTecCf (2012-07-11 05:36:57)


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

Offline

 

#3 2012-07-11 07:23:37

Deathray957
New Scratcher
Registered: 2012-06-15
Posts: 2

Re: Have sprites swap positions with each other

It works, thanks!

Offline

 

Board footer