views:

400

answers:

4

I am converting a room editor I had made in AJAX to Flash where users can move furniture around where they want, but I am running into some issues with the x,y coordinates. With the Javascript/AJAX setup, I recorded the X,Y coordinates of the furniture image, and it worked fine from the top left corner of the image. However, now trying to make it work, and load the same setups into Flash instead of with AJAX, the placement is all off. It appears that X,Y coordinates that are returned to me are from the center of the image instead of from the top left (if I drag something to the top left corner of a "room," it shows X & Y as being half of the width and height).

Any reason why this would be? I as under the impression the X,Y coordinates worked the same in both Javascript and Flash.

+1  A: 

Ensure that each object's registration point is at its top left corner, and not at its center.

More information:

Ron DeVera
How would I go about checking that if the objects are loaded in from an XML file?
James Simpson
A: 

Would it be reasonable as a work around to simply translate the location using the height and width of the object. For example say a object was 100px by 100px. If you moved it to the top left corner the coordinates would read 50x50y. On import can you simply add half the width and height to the X and Y respectively. On export just subtract half of it. This is assuming of course that the registration point is always in the middle.

+1  A: 

I would assume that you are doing all of this with the Flash IDE, because had you loaded this all at runtime with purely code, you would have went out of your way to force these to center by specifying an x and y that is half it's height and width. This all leads me to believe that you have put these into movieclips that you created with a centered registration.

You need to check the x,y of the bitmaps you are using as furniture. Make sure that they are at 0,0 inside their parent movieclips. Then you simply move the parent around. If your bitmaps have negative values of half their width and height as their x and y values, this would center your bitmap in the middle of the MovieClip/Sprite as opposed to having a top-left registration.

If you created a movieclip with centered registration, you do not have to destroy it a make a new one with another registration; Merely open the movieclip and set the bitmap/asset that is inside to a position of X: 0, Y: 0, then leave from inside the movieclip and once on the outside you will have to adjust it accordingly.

blog.hodgedev.com hodgedev.com

Brian Hodge