Page 2 of 2

Re: slideToObjectPos : uncertain final position

Posted: 26 November 2019, 15:49
by sourisdudesert
You are of course free to develop your own slide/place method.

However I would recommend the approach I suggested above.

Re: slideToObjectPos : uncertain final position

Posted: 26 November 2019, 18:46
by VanHlebar
So in my game I removed the zoom items on my two objects that I have been moving around. If I use placeOnObjectPos() I can get the objects to go to th exact spot I would like them to be on.

If however I use placeOnObject() and define the top/left locations in the CSS div it doesn't work. Am I doing someting wrong or is this a similar issue that is being discussed?

Example:

.tpl file

Code: Select all

<div id=granada_king>
</div>
css file

Code: Select all

#granada_king
{
	position: absolute;
	top: 450px;
	left: 455px;
}
If if remove the items from the css file except the postion then this works:

Code: Select all

this.placeOnObjectPos( 'kingIcon', 'grandada_king', 450, 455);
However if I try to leave the information in my css file and call it like this, the icon goes off into the middle of my map.

Code: Select all

this.placeOnObject( 'kingIcon', 'granada_king');
It appears that when using the placeOnObject() my div gets an extra element.style with attributes of:

Code: Select all

height: 42px;
top: -824px;
left: 447px;
I have no idea where these are coming from and can only assume it is getting injected by the placeOnObject call?

If I use the placeOnObjectPos() then the element.style is still different than my co-ordinates in my call, but the object goes to the location I would expect.

Code: Select all

height: 42px;
top: -664px;
left: 442px
I guess I am wondering if this is normal and expected or if I am messing something up without knowing it. :)

Thanks,
Eric

Re: slideToObjectPos : uncertain final position

Posted: 26 November 2019, 19:19
by Een
This seems normal and expected :)

(placeOnObject() centers the mobile object in the destination while placeOnObjectPos() positions it at the given coordinates inside the destination; the computed coordinates are added to the initial coordinates, so if some initial coordinates are defined in the css it will offset the dynamic positioning)

Re: slideToObjectPos : uncertain final position

Posted: 26 November 2019, 20:49
by VanHlebar
Een wrote: 26 November 2019, 19:19 This seems normal and expected :)

(placeOnObject() centers the mobile object in the destination while placeOnObjectPos() positions it at the given coordinates inside the destination; the computed coordinates are added to the initial coordinates, so if some initial coordinates are defined in the css it will offset the dynamic positioning)
Great thanks for the clarification and education! :)

Re: slideToObjectPos : uncertain final position

Posted: 22 August 2021, 08:21
by stefano
I have this issue with 2 of my games...

I use divs with % left/top values. slideToObjectPos seems to work with some set of resolutions of the screen, but, with some other resolutions it gets crazy.

I don't have any transform in my css except "transform-origin: center center;"

What can be the solution ? Is there any custom method for slideToObjectPos that uses % instead of px ?

Re: slideToObjectPos : uncertain final position

Posted: 22 August 2021, 08:37
by stefano
This should be the original code of the funcion:

Code: Select all

		slideToObjectPos: function (t, i, n, o, a, s) {
            if ('string' == typeof t) var r = $(t);
             else r = t;
            var l = this.disable3dIfNeeded(),
            d = dojo.position(i),
            c = dojo.position(t);
            void 0 === a && (a = 500);
            void 0 === s && (s = 0);
            if (this.instantaneousMode) {
              s = Math.min(1, s);
              a = Math.min(1, a)
            }
            var h = dojo.style(t, 'left'),
            u = dojo.style(t, 'top'),
            p = {
              x: d.x - c.x + toint(n),
              y: d.y - c.y + toint(o)
            },
            m = this.getAbsRotationAngle(r.parentNode),
            g = this.vector_rotate(p, m);
            h += g.x;
            u += g.y;
            this.enable3dIfNeeded(l);
            var f = dojo.fx.slideTo({
              node: t,
              top: u,
              left: h,
              delay: s,
              duration: a,
              easing: dojo.fx.easing.cubicInOut,
              unit: 'px'
            });
            null !== l && (f = this.transformSlideAnimTo3d(f, r, a, s, g.x, g.y));
            return f
          },
			

Re: slideToObjectPos : uncertain final position

Posted: 22 August 2021, 10:02
by Een
transform does mess up the coordinates for slideToObject/placeOnObject
When using transform, you need to disable it before / reenable it after any call to these functions for them to work reliably.

NB: why would you need transform-origin if you don't use transform?

Re: slideToObjectPos : uncertain final position

Posted: 22 August 2021, 14:25
by stefano
I have implemented my version of SlideToObjectPos and now everything looks great. Objects are moved in percentage position and not in px anymore.