![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
![]() |
|
|||||
|
Регистрация: Sep 2005
Адрес: Минск
Сообщений: 389
|
Коллеги, вот есть проблемка с алгоритмом.
Представим себе карту некого участка, которую можно зумить с помощью ползунка (_xscale: 100 - 1100) и драгать мышкой в видимой области (mask_mc). Не удается однозначно хорошо решить следующую задачу: Если карта увеличена и драгнута в любом направлении - мне не удается правильно возвращать ее координаты в начальные при обратном зуме до 100%. Ниже выкладываю код: stop(); /////////////////////////////////////////////////////////////////////////// MASKING map_mc.setMask(mask_mc); /////////////////////////////////////////////////////////////////////////// VARS var prevZoom:Number = 100; var newZoom:Number = 100; var deltaZoom:Number = 0; var zoomCoef:Number = 0; // var x0:Number = 328; var y0:Number = 185; /////////////////////////////////////////////////////////////////////////// FUNCTIONS zoomFunc = function () { prevZoom = zoomCoef + 100; // zoomCoef = Math.floor((zoom_mc.slider_mc._y - zoom_mc.line_mc._y) * 1000 / (zoom_mc.line_mc._height - zoom_mc.slider_mc._height)); // newZoom = zoomCoef + 100; map_mc._xscale = map_mc._yscale = newZoom; // deltaZoom = prevZoom - newZoom; // deltaX = Math.floor(x0 - map_mc._x); deltaY = Math.floor(y0 - map_mc._y); // if (map_mc._xscale > 100) { map_mc._x -= Math.floor(deltaX * deltaZoom / (100 - map_mc._xscale)); map_mc._y -= Math.floor(deltaY * deltaZoom / (100 - map_mc._yscale)); } else { map_mc._x = x0; map_mc._y = y0; } // }; /////////////////////////////////////////////////////////////////////////// ZOOM zoom_mc.slider_mc.onPress = function() { startDrag(this, false, this._x, zoom_mc.line_mc._y, this._x, zoom_mc.line_mc._y + zoom_mc.line_mc._height - this._height); var currY:Number = this._y; this.onEnterFrame = function() { if (this._y != currY) { zoomFunc(); currY = this._y; } }; }; // zoom_mc.slider_mc.onRelease = zoom_mc.slider_mc.onReleaseOutside = function () { stopDrag(); delete this.onEnterFrame; }; /////////////////////////////////////////////////////////////////////////// SCREEN DRAG map_mc.onPress = function() { startDrag(this, false, x0 + this._width / 2 - mask_mc._width / 2, y0 + this._height / 2 - mask_mc._height / 2, x0 - this._width / 2 + mask_mc._width / 2, y0 - this._height / 2 + mask_mc._height / 2); }; // map_mc.onRelease = map_mc.mapIns_mc.onReleaseOutside = function () { stopDrag(); }; Ключевые строчки: map_mc._x -= Math.floor(deltaX * deltaZoom / (100 - map_mc._xscale)); map_mc._y -= Math.floor(deltaY * deltaZoom / (100 - map_mc._yscale)); Добавлено через 30 минут Приложу еще ссылку, чтобы было понятно, о чем вообще речь: http://mightypixel.ru/truville/map_demo/ |
![]() |
![]() |
Часовой пояс GMT +4, время: 05:55. |
|
|
« Предыдущая тема | Следующая тема » |
|
|