Flex 滚动超过 10.000 像素

发布于 2024-11-04 07:52:53 字数 149 浏览 0 评论 0原文

Flex Canvas 容器的尺寸限制为 10,000x10,000 像素。然而,我见过 Flex 应用程序的滚动距离超过 10,000 像素。知道如何做到这一点吗?

我想要滚动的内容已经是分段的,但我需要将这些分段添加到可以垂直滚动超过 10,000 像素的内容中。

The Flex Canvas container is limited to 10,000x10,000 pixels. Yet, I've seen Flex apps that are scrolling way more than 10,000 pixels. Any idea how this can be done?

The content I want to scroll is in pieces already, but I need to add those pieces to something that can scroll vertically more than 10,000 pixels.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘亓 2024-11-11 07:52:53

根据您实际想要显示的内容,您可以将内容拆分为图块。这就是 Google 地图的工作原理,每次移动地图时,程序都会确定哪些图块在屏幕上可见并将其加载。地图上的任何标记或叠加层都会收到地图已移动的通知,并确定其新位置是。如果它们的位置超出屏幕,则可以将其从画布中删除。例如,Google 地图上缩放级别为 20 时所有图块的宽度为 (256 像素 * 2^20),等于总像素 268,435,456。

本质上,您只需要创建一个特殊的 Sprite 来跟踪它应该定位的实际 x,y 位置。每当容器移动时,您只需迭代所有子对象并确定将它们放在哪里。

function onCanvasScroll() {
    //determine the top left coordinates of the canvas
    //you will figure out how to do this depending on how the scrolling window
    //is implemented
    var canvas_scroll_x;
    var canvas_scroll_y;

    //create a bounding box for the canvas
    var view_bounds = new Rectangle(canvas_scroll_x, canvas_scroll_y, canvas.width, canvas.height);

    for (child in canvas) {
        var x = child.actual_x - view_bounds.x;
        var y = child.actual_y - view_bounds.y;

        var childBounds = new Rectangle(x, y, child.width, child.height);
        //determine if the component is visible on screen
       if (view_bounds.intersects(child_bounds)) {
          child.visible = true;
          child.x = x;
          child.y = y;
       }
       else {
           child.visible = false;
       }

    }
}

因此,如果您有一个位于 (100, 20000) 的画布、一个位于 (300, 20100) 的精灵和一个位于 (640,408) 的窗口,那么您可以将其放置在 (200, 100) 处,并且它会在屏幕上可见。

更好的方法不是仅仅将可见设置为 true 或 false,而是当项目不在视图范围内时从画布中完全删除它们。

Depending on what you actually want to display you may be able to split your content into tiles. This is how Google Maps works, every time the map is moved the program determines which tiles are visible on the screen and loads them in. Any markers or overlays that are on the map are notified that the map has moved and determine where their new location is. If their location is off the screen they can be removed from the canvas. For example, the width of all the tiles at zoom level 20 on Google Maps is (256 pixels * 2^20) which equals 268,435,456 total pixels.

Essentially you just need to create a special Sprite that keeps track of the actual x,y location it is supposed to be positioned at. Any time the container moves you simply iterate through all of the child objects and determine where to put them.

function onCanvasScroll() {
    //determine the top left coordinates of the canvas
    //you will figure out how to do this depending on how the scrolling window
    //is implemented
    var canvas_scroll_x;
    var canvas_scroll_y;

    //create a bounding box for the canvas
    var view_bounds = new Rectangle(canvas_scroll_x, canvas_scroll_y, canvas.width, canvas.height);

    for (child in canvas) {
        var x = child.actual_x - view_bounds.x;
        var y = child.actual_y - view_bounds.y;

        var childBounds = new Rectangle(x, y, child.width, child.height);
        //determine if the component is visible on screen
       if (view_bounds.intersects(child_bounds)) {
          child.visible = true;
          child.x = x;
          child.y = y;
       }
       else {
           child.visible = false;
       }

    }
}

So if you have a canvas that is positioned at (100, 20000), a sprite that is positioned at (300, 20100), and a window that is (640,408), you would place it at (200, 100) and it would be visible on the screen.

Instead of just setting visible to true or false a better approach would be to remove the items from the canvas entirely when they are not within the bounds of the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文