import { delay } from './delay.js' ; import { Laya } from 'Laya.js' ; import { Sprite } from 'laya/display/Sprite.js' ; class Main { constructor ( ) { Laya . init ( 800 , 600 ) ; Laya . stage . screenMode = 'none' ; this . test1 ( ) ; } /**
     * cacheas normal
     * 如果上层的clip改变了，cache好的内容必须要受到正确的影响。
     * 简单实现是暂时撤销cache
     */ async test1 ( ) { var sp1 = new Sprite ( ) ; sp1 . pos ( 100 , 100 ) ; Laya . stage . addChild ( sp1 ) ; sp1 . graphics . save ( ) ; sp1 . graphics . clipRect ( 10 , 10 , 120 , 120 ) ; sp1 . graphics . drawRect ( 10 , 10 , 120 , 120 , null , 'red' ) ; sp1 . graphics . restore ( ) ; var sp2 = new Sprite ( ) ; sp2 . pos ( 10 , 10 ) ; sp2 . graphics . drawRect ( 0 , 0 , 100 , 100 , 'green' ) ; sp2 . cacheAs = 'normal' ; sp1 . addChild ( sp2 ) ; await delay ( 1000 ) ; sp1 . graphics . clear ( ) ; sp1 . graphics . drawRect ( 10 , 10 , 300 , 300 , null , 'red' ) ; sp1 . graphics . clipRect ( 10 , 10 , 300 , 300 ) ; sp2 . pos ( 100 , 100 ) ; await delay ( 10 ) ; ( window as any ) . testEnd = true ; } } new Main ( ) ;