Arrange MovieClips by _height+_y

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 15th, 2007, 2:09 am

Anyone have a suggestion for arranging the depths of multiple MovieClips where the _y position plus _height of the MovieClip being larger would have the MovieClip at a higher depth ?

As soon as I started this thread I got an idea, (happens every time)

Isn't there 65000-someodd depths available ?
What about doing somthing like this ?
Code: [ Select ]
mc.onMouseMove = function(){
  this.swapDepths(this._y + this._height);
}
  1. mc.onMouseMove = function(){
  2.   this.swapDepths(this._y + this._height);
  3. }


Though I guess checking the depth first is a good idea, don't want MovieClips dissapearing all of a sudden.
Code: [ Select ]
mc.onMouseMove = function(){
  var wantedDepth:Number = this._y + this._height;
  while(this._parent.getInstanceAtDepth(wantedDepth) !== undefined){
   wantedDepth++;
  }
  this.swapDepths(wantedDepth);
}
  1. mc.onMouseMove = function(){
  2.   var wantedDepth:Number = this._y + this._height;
  3.   while(this._parent.getInstanceAtDepth(wantedDepth) !== undefined){
  4.    wantedDepth++;
  5.   }
  6.   this.swapDepths(wantedDepth);
  7. }


Before I started this thread my thoughts were along the lines of a for(iterator in object) loop & using hitTest, but that just kinda seems rediculas now. :scratchhead:

There's no way the Stage of this movie will ever get to 65000 pixels in height, not even with the _height of a MovieClip included.
Strong with this one, the sudo is.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 15th, 2007, 2:09 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 15th, 2007, 2:42 am

Yep, that second codeblock works like a charm.

Man, I wish I could show you guys what this is for, now.
It's been awhile since I've actually been excited about somthing I'm doing in Flash. :D
Strong with this one, the sudo is.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 15th, 2007, 3:40 am

Should have known it wouldn't be that easy.

It works, but with MovieClip.transform.matrix alterations applied, it's a little buggy. ;)
Strong with this one, the sudo is.
  • krismeister
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Oct 21, 2006
  • Posts: 202
  • Status: Offline

Post June 16th, 2007, 12:28 pm

thats an interesting workaround.

I didn't realize you could apply a depth of a non-whole number like: 5.02
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 16th, 2007, 2:55 pm

Chances are that the swapDepths method simply shaves any decimals from the end of the paramater before applying them.
Strong with this one, the sudo is.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Joined: Jul 11, 2005
  • Posts: 1828
  • Loc: In the Great White North
  • Status: Offline

Post June 16th, 2007, 8:11 pm

yeah i guess I didn't know that either. I've have used Math.round() to force a whole number...
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 16th, 2007, 8:56 pm

The issue I have now, is that there's a triangle area that doesn't want to cooperate.

If you look at the top of this image, you'll see what should happen, as in the yellowish screen shows closer than the darkish screen.

On the bottom of the image, you'll see what really happens, which is that when the yellowish screen wanders into that redish area, the depth of the MovieClips from 2D space figured from _height+_y have little meaning & the yellowish screen falls behind the darkish screen.

Image

I seem to be a little closer with hitTest(x,y,shapeFlag) where x & y are the bottom-right corner, or the bottom-middle of the wandering yellowish MovieClip but it's almost just as buggy.

The thing is, both of thoose screens in the image are dragable, their skews, scales, & reflections are updated in real time as they are dragged.

Offtopic: I wonder if the Bermuda Triangle is "gods" little clipping error. :scratchhead:
Strong with this one, the sudo is.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post June 21st, 2007, 5:40 am

lovely.
Is there any order in this chaos?
you said that _y position plus _height of the movie will bring it to front, but in your example it's not really like this.
Can't you establish a rule (of course, with some exceptions :D) so you can follow it when bringing the movieclips to front?
Can you show us an image with more shapes to see exactly what you're trying to do?
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • krismeister
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Oct 21, 2006
  • Posts: 202
  • Status: Offline

Post June 21st, 2007, 5:23 pm

This is interesting. I'm a little bit of 3d enthusiast myself.

If all your shapes are on the same 3-dimensional plane and are all oriented in the same direction then you might be able to assume that the the closer the bottom left corner of a rectangle shape -- not counting the shadow -- is to the bottom left of the stage the closer that shape is to you.

Does this work?

Code: [ Select ]
 // this _x and _y is from bottom left corner
 //(Stage.width- this._x) is how far from the right side

  var wantedDepth:Number = (Stage.width - this._x) + this._y;
  1.  // this _x and _y is from bottom left corner
  2.  //(Stage.width- this._x) is how far from the right side
  3.   var wantedDepth:Number = (Stage.width - this._x) + this._y;


and I have a feeling that depending on the perspective of the camera you'll need to weight x or y.

Code: [ Select ]
  var wantedDepth:Number = (Stage.width - this._x) + (1.2 * this._y);


If you didn't have so much built already I'd recommend a 3d framework like papervision or sandy.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post June 22nd, 2007, 12:05 am

I came across Papervision a few days ago, all I could find on that is that it's a "private beta" at the moment.

I'm looking at Sandy (and pixlib) now, if I can get the effect I'm going for without a huge filesize & CPU usage I may use it.
Strong with this one, the sudo is.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Joined: Nov 05, 2004
  • Posts: 1254
  • Loc: Ro
  • Status: Offline

Post June 22nd, 2007, 4:32 am

or just add a Z axis :D
Just check this:
http://www.tonypa.pri.ee/tbw/tut16.html
It's an isometric view .... so he calculates if the object is behind or in front of an object. Therefor i guess it's possible to do it for your objects too.
“True mastery transcede any particular art. It stems from mastery of oneself - the ability, developed throgh self-discipline, to be calm, fully aware, and complety in tune with oneself and the surroundings. Then, and only then, can a person know himself. ”
  • krismeister
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Oct 21, 2006
  • Posts: 202
  • Status: Offline

Post June 22nd, 2007, 5:00 am

If you sign up for the papervision list-serve they'll send you the SVN.

Another 2 packages to look into are:
Blitz agency posted a basic 3d package:
http://labs.blitzagency.com/?p=68
And wire-engine-3d - it doesn't yet allow 3d shapes to be clickable, but they do allow sprites to be clickable, which looks sorta like what you have.
http://osflash.org/we3d

I've worked with the AS2 stable sandy release of a couple months ago. It was seemed pretty slow with more than 40 shapes in the camera view.

AS3 performs alot better than AS2, so if you have an opportunity to start over, it might be a good idea to us AS3.
  • krismeister
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Oct 21, 2006
  • Posts: 202
  • Status: Offline

Post June 22nd, 2007, 5:31 am

IceCold's example was sweet. I like how you don't see anything like trig at all.

Post Information

  • Total Posts in this topic: 13 posts
  • Users browsing this forum: No registered users and 35 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.