最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ScrollZoom a pixi.js canvas - Stack Overflow

programmeradmin2浏览0评论

Below is an easy way to put some text on a pixi.js (using WebGL) canvas.

How can we scroll / zoom the displayed part of the canvas ? (i.e. mouse down + drag should move ...)

Example of what I would like to achieve : .htm

<!DOCTYPE HTML>
<html>
<head>
    <title>pixi.js example 1</title>
    <script src="pixi.js"></script>
</head>
<body>
    <script>
    var stage = new PIXI.Stage(0xFFFFFF);
    var renderer = PIXI.autoDetectRenderer(800, 600);
    document.body.appendChild(renderer.view);
    var text = new PIXI.Text("Hello World", {font:"50px Arial", fill:"black"});
  stage.addChild(text);
  renderer.render(stage);   
    </script>
    </body>
</html>

Below is an easy way to put some text on a pixi.js (using WebGL) canvas.

How can we scroll / zoom the displayed part of the canvas ? (i.e. mouse down + drag should move ...)

Example of what I would like to achieve : http://s419743653.onlinehome.fr/things/test2.htm

<!DOCTYPE HTML>
<html>
<head>
    <title>pixi.js example 1</title>
    <script src="pixi.js"></script>
</head>
<body>
    <script>
    var stage = new PIXI.Stage(0xFFFFFF);
    var renderer = PIXI.autoDetectRenderer(800, 600);
    document.body.appendChild(renderer.view);
    var text = new PIXI.Text("Hello World", {font:"50px Arial", fill:"black"});
  stage.addChild(text);
  renderer.render(stage);   
    </script>
    </body>
</html>
Share Improve this question edited Sep 13, 2014 at 13:44 Basj asked Sep 13, 2014 at 13:33 BasjBasj 46.7k110 gold badges458 silver badges808 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

set the scale property on the DisplayObjectContainer. In your case you don't have any so you can scale the stage.

stage.scale.x = 2;
stage.scale.y = 2;

or you can put your objects in a group and scale the group.

var group = new Pixi.DisplayObjectContainer();
group.scale.x = 2;
group.scale.y = 2;

group.add(text);
发布评论

评论列表(0)

  1. 暂无评论