Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swapping Image *Positions* 1

Status
Not open for further replies.

alebow

Technical User
Jun 9, 2006
2
US
Greetings all---new forum member here...

I am hitting a wall as to how to achieve the following in Director (I'm using 8.5):

I have 7 objects on the stage, and I want the user to be able to click two of them, have them each "highlight" (or otherwise show their status as "selected"), then, when a button is pressed (one which says, "Swap" or a synonym), the two selected objects trade positions. To complicate things further, I need the two objects to trade their positions *visibly*---not as an instantaneous "flip," but, rather, the user can see the first object travel to the second's position and vice versa.

I've only got rudimentary Lingo expertise and I'm fearing that I'm out of my depth here.

Any help that can be offered would be greatly appreciated.



Regards,

Adam
Los Angeles, CA
 
Let's start with the simplest example: swap locations of two objects.

The set up:
Place one object in Sprite 1, another object in Sprite 2. Place "Swap" button in Sprite 3.

The scripts:
1. Movie script:
[tt]--
on prepareMovie
global gSwapPList
gSwapPList = [:]
end prepareMovie
--[/tt]

2. Behaviour script attached to the "Swap" button:
[tt]--
on mouseUp me
global gSwapPList
if gSwapPList.length < 1 then
gSwapPList = [#1: [#sprite: 1, #x: sprite(1).locH, #y:sprite(1).locV], #2: [#sprite: 2, #x: sprite(2).locH, #y: sprite(2).locV]]
end if
end mouseUp
--[/tt]

3. Frame script:
[tt]--
on exitFrame me
global gSwapPList
if gSwapPList.count > 1 then
spriteA = sprite(gSwapPlist[#1][#sprite])
spriteATargetLocH = gSwapPlist[#2][#x]
spriteATargetLocV = gSwapPlist[#2][#y]
if spriteA.locH <> spriteATargetLocH then
spriteA.locH = spriteA.locH + (spriteATargetLocH - spriteA.locH)/10
end if
if spriteA.locV <> spriteATargetLocV then
spriteA.locV = spriteA.locV + (spriteATargetLocV - spriteA.locV)/10
end if
spriteB = sprite(gSwapPlist[#2][#sprite])
spriteBTargetLocH = gSwapPlist[#1][#x]
spriteBTargetLocv = gSwapPlist[#1][#y]
if spriteB.locH <> spriteBTargetLocH then
spriteB.locH = spriteB.locH + (spriteBTargetLocH - spriteB.locH)/10
end if
if spriteB.locV <> spriteBTargetLocV then
spriteB.locV = spriteB.locV + (spriteBTargetLocV - spriteB.locV)/10
end if
end if
go the frame
end
--[/tt]

Kenneth Kawamoto
 
Dear Kenneth:

Apologies for the one-week delay---I got sidetracked by totally unrelated projects...

Returning to this matter today, I found your post to be very smart, clean, simple, clear, and (as it turns out), highly effective.

It has served not only to solve my problem but as a Lingo programming lesson all of its own. It has helped me to deepen my understanding of how Lingo works with lists, handlers, etc. I am extremely grateful.


Warmest regards,

Adam LeBow
Los Angeles, CA, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top