create.js 开发小游戏(二)蒙版

Fork Me On Github
zodream 游戏 TypeScript 2020年05月

createjs 中物体是不会自动超出边界自动隐藏的,

例如,负坐标也不会在视野内隐藏

里面的每一个 DisplayObject 都是没有宽和高限制的

例如 createjs.Container 上面加个会动的 createjs.Shape, 我想让她 在 x: 0, y: 0, width: 600, height: 600 这个范围内可见,跑到其他地方不可见,该怎么办?

下面代码就可以实现,

ts
        

const box = new createjs.Container();
const shape = new createjs.Shape();

box.addChild(shape);
// 添加蒙版
const mask = new createjs.Shape(new createjs.Graphics().beginFill("#ffffff").drawRect(box.x, box.y, 600, 600));
box.mask = mask;
12345678

但请注意 mark drawRect 使用的时 box 的父坐标系统,不是 box 的坐标系统,

这并不能遮住 box 里面坐标 x 或 y 为负的,可以考虑 mark drawRect(box.x + x, box.y + y, 600 - x, 600 - y) 扩大蒙版的范围

点击查看全文
标签: createjs
0 240 0
Tween._inited does not reset if scene is being destroyed or removed inside the game and rebuild