viewComtent.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import GameConfig from "../../configData/GameConfig";
  2. import gameOver from "./gameOver";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export default class viewComtent extends cc.Component {
  6. private winsize:cc.Vec2 = null;
  7. public static instance: viewComtent = null;
  8. protected onLoad() {
  9. viewComtent.instance = this;
  10. let hhh = cc.winSize.height * (1920 / cc.winSize.width);
  11. this.node.setContentSize(1920, hhh);
  12. this.winsize = cc.v2(1920, hhh);
  13. }
  14. /**游戏结算 */
  15. public gameOver(Hpnum: number) {
  16. let self = this;
  17. cc.resources.load("prefabs/over", cc.Prefab, function (err, prefab: cc.Prefab) {
  18. var newNode = cc.instantiate(prefab);
  19. self.node.addChild(newNode, 1);
  20. newNode.setPosition(cc.v2(0, 0));
  21. let iver = newNode.getComponent(gameOver);
  22. iver.gameiswin(Hpnum);
  23. });
  24. }
  25. /**获取屏幕真是大小 */
  26. public getWinsize():cc.Vec2
  27. {
  28. return this.winsize;
  29. }
  30. /**获取偏移量 */
  31. public getOff(): number {
  32. let scroll = this.node.parent.getComponent(cc.ScrollView);
  33. // console.log("最大偏移量:"+scroll.getMaxScrollOffset());
  34. return scroll.getMaxScrollOffset().y-scroll.getScrollOffset().y;
  35. }
  36. }