SPHERETOSCREEN action works a bit strangely

  • Hello, I'm trying to make a moving layer [tag] match the position of a series of hotspots on the onover event, for that I'm using a style with:

    Code
    onover="spheretoscreen(hotspot[get(name)].ath,hotspot[get(name)].atv,layer[tag].x,layer[tag].y);"

    It mostly works well, but when the hotspots are located nearer to the edge of the screen then the center of the layer and the hotspot begin to proportionally mismatch, it actually starts to go beyond depending on the side the hotspot is in (or up or down), I'm posting three images so you understand the problem.

    My question is, is there any way to correct this mismatching alignment, I'd like to see the layer centered right on the hotspot no matter where in the screen it is.

    Thank you

  • Thank you very much, Sachagriffin, I never thought hotspots could be parents to layers! I set it manually and it works great

    Code
    set(layer[tag].parent,hotspot[hs1]));

    but I ran into problems while trying to change it dynamically:

    Code
    <style name="infos"
     onhover="tag_call();"/>
    
    
    <action name="tag_call">
    set(layer[tag].parent,get(hotspot[get(name)].name));
    </action>

    it gives me the error 'No parent "hs1" found' and of course nothing happens. Do you have any ideas on what might be happening?

    Thank you very much again!

  • IT WORKED!!!

    the final code line was:

    Code
    txtadd(layer[tag].parent,'hotspot[',get(name),']');

    Thank you so much, Sachagriffin!

    And, going back to the opening subject of this thread, is something wrong with the action spheretoscreen?, It should work exactly as this fix you gave me, but it doesn't.

  • Hello, I have successfully with the kind help from Sachagriffin made a layer have multiple parent hotspots and move from one to another on the onhover event. The thing is that in the Flash version the children layer acts as an extension of the hotspot (it can be clicked on and hovered) and I don't want this to occur, I set children="false" in the hotspot style and the layer is set enabled="false "which works great in HTML5, but in Flash it doesn't seem to work.

    Do you have any ideas on what can I do to fix this?

  • Maybe i'm wrong and misunderstand but maybe you can forget the parent thing and just pass the x and y (after spheretoscreen calculation) and maybe some vars from the hotspot to the layer?

    Do you have a link so we can see?

    Tuur *thumbsup*

  • Hello, Tuur!, your instinct is right on the spot, however I've done that (actually I tried that before anything else) and the results were not what I expected, you can see in my other post how it turned out with the spheretoscreen action:

    SPHERETOSCREEN action works a bit strangely

    It almost works well but not entirely, there's some strange behaviour happening that I cannot understand and think is more a bug than anything else, Sachagriffin suggested this new method of parenting the layer with the hotspots and it works great, except for this little problem I described above. It seems like the children attribute doesn't work in flash, or at least in my flash browser.

    I'm still working on the project but I will post an example soon!

  • Hi,

    please note that there is here a fundamental real and mathematical limitation - when the 3d-world positions of the hotspots are 'behind' the screen, it not possible to project them to 2d-screen coordinates.

    I have tried to illustrate the case here - look at the 'projection rays' from the center to the screen:
    spheretoscreen for hotspots outside the viewport

    The spheretoscreen() action would return 'NaN' (Not-A-Number) for these out-of-screen-plane cases.

    You could add a check like this to check the values and set the layer invisible for this case:

    Code
    spheretoscreen(h,v,x,y);
    set(is_visible,true);
    if(x != 0, ifnot(x, set(is_visible,false); ));
    copy(layer[NAME].visible, is_visible);
    if(is_visible, copy(layer[NAME].x,x); copy(layer[NAME].y,y); );

    Best regards,
    Klaus

  • Klaus, thank you for the answer, I think I understand the problem, but in my case I don't want to obtain the screen coordinates of a hotspot outside of the viewing area, instead I want to match the coordinates of a layer with the screen coordinates of a hotspot, that's why I used the spheretoscreen action, the problem is that there is a noticeable delta in X and Y happening proportionally to where in the screen the hotspot is, as you see in the pictures above the layer tends to go beyond the coordinates of the hotspot depending on which side of the screen it is. I traced both the x and y of the layer and the spheretoscreen coordinates of the hotspot. They match almost perfectly (there is a variation of about .0000000005 pixels), but visually they are obviously on different positions, that's the main issue I ran into, I'm not sure if this is related to the problem you explained or not.

    Another thought that occured to me was that when I made the hotspots parents of the layer, somehow the computer had to calculate these coordinates and make them match, at least that's what comes to mind, so it's working perfectly that way but not through the spheretoscreen action.

    Any thoughts?

  • the problem is that there is a noticeable delta in X and Y happening proportionally to where in the screen the hotspot is

    In this case I would say that the the wrong edge settings is used...

    The hotspot itself is aligned with its 'edge' point at the ath/atv coordinates (additionally optionally shifted the ox/oy settings).

    Best regards,
    Klaus

  • I finally discovered what whas going on, I had a flying="0.01" in the hotspot style, that's why it was moving them around suspiciously.

    My mistake, the action screentosphere/spheretoscreen works great!

    Alberto.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!