Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 13 of 13

Thread: The baddest Flash discovery you will see today

  1. #1

    The baddest Flash discovery you will see today

    globalToLocal() is broken.
    globalToLocal() is broken.
    globalToLocal() is broken.
    globalToLocal() is broken.
    globalToLocal() is broken.

    Any questions?

    So anyway, localToGlobal works fine. However globalToLocal is so broken it looks like some really bad use of sin() is going on. With it off, translating a point through a rotated object is fine. With it ON objects weave in and out of the screen and flicker every second frame. Which is exactly what happened when I originally wrote my own version of this function and got it completely wrong.

    Fix it Macromedia.

  2. #2
    provide an example

  3. #3
    Uno momento.

  4. #4
    http://darken.spark.lithotech.co.nz/globaltolocal.zip - 15mb

    Apologies for the large size. Here's the only difference between these two movies:

    Working:
    Code:
    function update_location() {
    	var point:Object = {x: this.initial_x, y: this.initial_y};
     	_root.World.Ground.Ground_Rotation.Ground_Position.Map.localToGlobal(point);
    	//this.globalToLocal(point);
    	this._x = point.x;
    	this._y = point.y;
    }
    Not working:
    Code:
    function update_location() {
    	var point:Object = {x: this.initial_x, y: this.initial_y};
    	_root.World.Ground.Ground_Rotation.Ground_Position.Map.localToGlobal(point);
    	this.globalToLocal(point);
    	this._x = point.x;
    	this._y = point.y;
    }
    In the end I got around the globalToLocal requirement by moving most of my movie's container objects to 0,0. Previously they were centered on the screen, which was just a nih-friendly thing.

    Another thought that just occurred to me is that I have my processor overclocked. This can definitely affect which type of math operations are selected by programs, so let me know if in fact both of these movies work. The globalToLocal.swf should display the behaviour I'm talking about though.

  5. #5
    15mb is too big for me and I cant tell what you have going on there based on your code but Im a little confused in where the globalToLocal comes into play when it works without it? If it works, why have it at all?

    Anyway, the biggest problem people have with these methods (and what may be your problem) is properly scoping them. For example, lets say you have this movie clip

    _root.World.Ground.Ground_Rotation.Ground_Position .Map

    And you want to position Map based on a global point. To convert that global point to a position for map, you would use

    _root.World.Ground.Ground_Rotation.Ground_Position .globalToLocal(point);

    since Map's positioning is based in the coordinate space of it's parent, Ground_Position.

  6. #6
    It gets trickier than that. These are my two paths:

    _root.World.Ground.Ground_Rotation.Ground_Position .Map
    _root.Pawns

    Inside the path at the top are empty spawner objects. They create objects inside the _root.Pawn, hence the localtoGlobal then the globalToLocal. In this case it was safe enough to relocate Pawns to 0,0 and drop the globalToLocal as you said.

    Ground_Rotation and Ground_Position as you may have guessed are getting all the transformations. The spawner object is actually much deeper inside that path, but we work out its position relative to the Map object (this.initial_x and this.initial_y) and use this as a point of reference instead, as the map tiles (and spawners) are loaded dynamically.

    This is exactly what globalToLocal was designed for, and not having it working is a bit frustrating. At this point I would bank money on it not functioning correctly, although the reason escapes me. I'm starting to think overclocking and I'll try adjusting this later, in the meantime somebody who treats their PC gentler is welcome to let me know their own results.

  7. #7
    Also, just to check off every avenue I do indeed (or was trying to) localise the points relative to _root.Pawns and not its child object.

  8. #8
    I dont know if this will help or not
    Attached Files Attached Files

  9. #9
    This is close to the structure I have, but not quite. In any case it looks like pairing up localToGlobal and globalToLocal is a bad idea, but individually they're ok.

  10. #10
    that example uses them together just fine

  11. #11
    Yeah, but as I said - it doesn't mirror the structure I have here nor any of the other factors that could be influencing it to break.

    No matter, this wasn't really a query for help but I was trying to see if anyone else was experiencing this.

  12. #12
    I dont even think it was that. I think you were claiming that it was broken ... and I dont think it is. I just think there's a small bug in your code somewhere that is giving unexpected results, whether it be a scoping issue or whatever.

  13. #13
    Not at all. I'll explain my logic. For the sake of an example, here's two paths:

    _root.someobject.rotatedobject.movedobject.blob
    _root.someholder

    First instance:
    The top path has been transformed at various stages in the path. The second path is also transformed, but its just being offset and not rotated. In this instance we see movement of the objects on the terrain to be remarkably similar to the pink curve in this diagram. This indicates a missing step in a sin/cos calculation.

    Second instance:
    We relocate the second path to 0,0 thereby removing all transformations on it. At this point using globalToLocal() on that object should result in the values supplied being returned with no change made on them. Except that isn't what happens, and we still get the Taylor curve mentioned above.

    Third instance:
    With the second path at 0,0 we don't actually need to do another globalToLocal(). We remove it and the movie works perfectly.

    If globalToLocal() were working and if it was indeed a bug in my code, instances two and three would produce the same results. It's simple, basic geometry.

    The error could absolutely be caused by something else I'm doing somewhere in the movie - in fact I'm banking on it. A function that breaks with no interference whatsoever wouldn't make it into production, but some internal math or path operation that breaks under certain circumstances would.

    What we have here is a bug, and by the looks of it nobody else has encountered it yet. Whatever, I'm going to pass it along to whoever thinks it's their job to fix it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012