Articles Archive
Articles Search
Director Wiki
 

Discovering locZ

June 18, 2000
by Pat McClellan

Dear Multimedia Handyman,

I just got Director 8 and I'm working on my first project. Basically it's a simple drag 'n drop jigsaw puzzle that's pretty much done. However, when the pieces are all scattered and you begin to drag, some pieces get hidden 'cause they're behind other pieces. I would like to have the piece automatically move to the front on mouse down. It doesn't seem too hard to accomplish, but I've had the hardest time making it work...please help me!

Robert

Dear Robert,

There are a couple of ways to do what you're talking about. The first method is to dynamically change which members are in a series of sprite channels, with the effect of changing the Z-axis order of the members. I wrote an article about this called Dynamic Sprite Re-ordering -- which is really a bit of a misnomer because the sprites don't reorder themselves, the cast members do. Here's a demo movie that shows how it works -- I call it "popTop" because the card you click on pops to the top sprite channel.

Director 8 download for Mac or Windows.

Notice that when you click on a card, the property list below the cards changes to show you which cards are in which sprite channels. After you release the mouse, the card cast members remain in the new sprite channels. This works great for a deck of cards, but it might be more processing than is necessary if you have hundreds of sprites. So let's look at another way to do what you describe in your question... by "faking it."

In the demo, click on the button that says "go fakeZ". You'll see that you can still pop a card to the top when you click on it, but when you release it, it reverts to its original z-axis order. Watch the list at the bottom of the demo and notice that the members do not change sprite channels at all.

When Director renders the stage, from sprite 1 up to the highest sprite channel, you can give it some special instructions. There's a new sprite property in Director 8 called locZ, which allows you to set which rendering layer the sprite is in. The higher the number, the more "on top" it is.

So, here's a behavior you can drop on your puzzle pieces to make them pop to the top when the mouse is down...and then revert to their normal layer on mouseUp.

property pSprite

on beginSprite me
  pSprite = sprite(me.spriteNum)
end beginSprite

on mouseDown me
  pSprite.locZ = 500
end mouseDown

on mouseUp me
  pSprite.locZ = me.spriteNum
end mouseUp

on mouseUpOutside me
  mouseUp me
end mouseUpOutside

All the behavior does is change the locZ of the sprite for the duration of the mouseDown. In this case, I used a "virtual" sprite channel of 500, but you could make this any number higher than the number of the sprite channel in which you have other sprites. Just for fun, I checked to see what would happen if you set the locZ to 0 or to a negative number. Sure enough, it renders the sprite behind the stage. I can actually see it behind the stage in authoring, thanks to D8's ability to have the stage window larger than the stage.

There you have your choice of solutions, and a tasty bit of new Lingo as well! Good luck with your project.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.