AutoFitLayer.js 689 B

123456789101112131415161718192021222324252627282930313233
  1. (function(cjs){
  2. var lib, p;
  3. lib = {};
  4. (lib.AutoFitLayer = function(){
  5. this.initialize();
  6. }).prototype = p = new cjs.Container;
  7. p.doLayout = function(){
  8. if(this.getNumChildren() == 0) {
  9. return;
  10. }
  11. var o = this.getBounds();
  12. var r = new FandlrGame.geom.Rectangle(o.x, o.y, o.width, o.height);
  13. r.resizeTo(stage.canvas.width, stage.canvas.height);
  14. this.scaleX = this.scaleY = r.width/o.width;
  15. this.x = r.x;
  16. this.y = r.y;
  17. };
  18. p.pAddChild = p.addChild;
  19. p.addChild = function(item, refresh) {
  20. if(refresh == undefined) {
  21. refresh=false;
  22. }
  23. this.pAddChild(item);
  24. if(refresh) {
  25. this.doLayout();
  26. }
  27. }
  28. cjs.AutoFitLayer = lib.AutoFitLayer;
  29. })(createjs);