Note that there are some explanatory texts on larger screens.

plurals
  1. PODrag and Drop stage scrolling algorithm problems
    primarykey
    data
    text
    <p>I have some problems with basic drag and drop scrolling algorithm. Here is my algorithm:</p> <ol> <li><p>When mouse pressed down i set boolean dragging = true and store the current mouse x and y position in stored_position variable.</p></li> <li><p>When mouse up i set boolean dragging = false.</p></li> <li><p>On each frame i check dragging == true and if it is i calculate the dx = current_mouse.x - stored_position.x and dy = current_mouse.x - stored_position.y. Then i store current mouse position as the new stored_position and scroll my view (it is 2d camera object) by this dx dy, as the Camera.x -= dx, Camera.y -= dy (i need the inversion one because of camera specific).</p></li> </ol> <p>The problem with this algorithm is that when i drag the camera it starting to blink and move around/shake. I think it is because when i move my mouse from left to right it traces dx like this:</p> <pre><code>71 -67 69 -68 69 -68 8 -5 </code></pre> <p>So i think it is the mouse twitching(i mean the mouse is jumps back sometimes when we try to draw a line). Any idea of changing algorithm, maybe i miss something? Here is example of this problem: <a href="https://dl.dropbox.com/u/78904724/as_host/buld_build_other.rar" rel="nofollow">https://dl.dropbox.com/u/78904724/as_host/buld_build_other.rar</a> (you need to run the index.html chose the level and try to drag the screen).</p> <p><strong>Updated</strong> Here is the example full source link (this is the random picture, i swear): <a href="https://dl.dropbox.com/u/78904724/as_host/scroll_test.rar" rel="nofollow">https://dl.dropbox.com/u/78904724/as_host/scroll_test.rar</a> And this is the code i used (in example i use native flash events instead of using axgl checks to not confuse someone, i have both examples and it cause the same problems):</p> <pre><code> //variables with comments private var dragging:Boolean = false; //dragging flag private var current_mouse:Array; //stored mouse position array [0] - x, [1] - y private var d:Array; //dx dy array [0] - x, [1] - y [Embed(source = "test.jpg")] public static const _sprite:Class; //sprite graphics private var view_sprite:AxSprite; //some image on the stage to drag it //this is the class constructor code view_sprite = new AxSprite(0, 0, _sprite); add(view_sprite); current_mouse = new Array(); d = new Array(); Ax.stage2D.addEventListener(MouseEvent.MOUSE_DOWN, function(e:MouseEvent):void { current_mouse[0] = Ax.mouse.x; current_mouse[1] = Ax.mouse.y; dragging = true; }); Ax.stage2D.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent):void { dragging = false; }); Ax.stage2D.addEventListener(MouseEvent.MOUSE_MOVE, function(e:MouseEvent):void { if (dragging) { d[0] = Ax.mouse.x - current_mouse[0]; d[1] = Ax.mouse.y - current_mouse[1]; Ax.camera.x -= d[0]; Ax.camera.y -= d[1]; current_mouse[0] = Ax.mouse.x; current_mouse[1] = Ax.mouse.y; } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload