javascript - 为什么 easelJS 缩放我的 Sprite ?

标签 javascript canvas sprite easeljs createjs

我正在使用 EaselJS 在 Canvas 中创建动画背景。我想知道为什么我将 Canvas 设置为窗口大小后立即缩放我的 Sprite ...... 图像看起来被拉伸(stretch)了......

$('body').append(''); $('#backgroundCanvas').height($(window).height()); $('#backgroundCanvas').width($(window).width());


var sprite = new createjs.SpriteSheet({
          "animations":
            {
                "run": [0, 6, "run", frequency]},
                "images": [url],
                "frames":
                    {
                        "height": height,
                        "width":width,
                        "regX": 0,
                        "regY": 0,
                        "count": count
                    }
            });
                    var item = new createjs.BitmapAnimation(sprite);    
                    item.height = height;       
                    item.width = width;             
                    //item.scale = item.scaleY = item.scaleX= 0.5;  
                    item.x = positionX;         
                    item.y = positionY;
                    item.dirX = 1;  
                    item.dirY = 1;      
                    item.vX = 4;            
                    item.vY = 4;


                    item.gotoAndPlay("run");

                    stage.addChild(item);

最佳答案

当您使用 CSS 缩放 Canvas 时,它会缩放内容,因为它的像素数相同。使用 JavaScript 对其进行缩放(设置宽度和高度属性),它会更改像素数量,并且不会拉伸(stretch)您的内容。

干杯。

关于javascript - 为什么 easelJS 缩放我的 Sprite ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15574890/

相关文章:

javascript - onchange 函数动态更新的问题

javascript - 使用 jQuery 转换一个 div 来显示另一个

javascript - 如何获取 firebase 数据库的主要对象?

javascript - D3JS 力网 : Links to nodes that are grouped using formula in transform fnt

Html 5 Canvas 完整箭头

Phaser 中的旋转和 getBounds()

android - 二进制 XML 文件行 #0 : Error inflating class

javascript - 用 Canvas 绘制的星爆形状看起来非常像素化(锯齿)

c++ - 数组/vector 中的 SFML 2.0 c++ Sprite

c++ - Direct3D 奇怪的崩溃