Arrange MovieClips by _height+_y

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Should have known it wouldn't be that easy.

It works, but with MovieClip.transform.matrix alterations applied, it's a little buggy. ;)
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

thats an interesting workaround.

I didn't realize you could apply a depth of a non-whole number like: 5.02
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Chances are that the swapDepths method simply shaves any decimals from the end of the paramater before applying them.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

yeah i guess I didn't know that either. I've have used Math.round() to force a whole number...
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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:
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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?
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

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
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

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.
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

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
  • krismeister
  • Posts: 202

Post 3+ Months Ago

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 38 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.