Advertisement
Guest User

clouds script

a guest
Jun 3rd, 2023
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.90 KB | None | 0 0
  1.  
  2. addLoadEvent(function () {
  3.  
  4. var cloundsInitialized = false;
  5.  
  6. function initHeaderClouds() {
  7.  
  8. var imagesLoaded = 0;
  9.  
  10. var cloud1 = {
  11. url: 'https://lorwolf.azureedge.net/layout/Header-Clouds-1-v2.png',
  12. loaded: false,
  13. }
  14.  
  15. var cloud1Behind = {
  16. url: 'https://lorwolf.azureedge.net/layout/Header-Clouds-2-v2.png',
  17. loaded: false,
  18. }
  19.  
  20. var cloud2 = {
  21. url: 'https://lorwolf.azureedge.net/layout/Header-Clouds-1-v2.png',
  22. loaded: false,
  23. }
  24.  
  25. var cloud2Behind = {
  26. url: 'https://lorwolf.azureedge.net/layout/Header-Clouds-2-v2.png',
  27. loaded: false,
  28. }
  29.  
  30. var cloud3 = {
  31. url: 'https://lorwolf.azureedge.net/layout/Header-Clouds-1-v2.png',
  32. loaded: false,
  33. }
  34.  
  35. var cloud3Behind = {
  36. url: 'https://lorwolf.azureedge.net/layout/Header-Clouds-2-v2.png',
  37. loaded: false,
  38. }
  39.  
  40. function imageLoaded() {
  41. imagesLoaded++;
  42. if (imagesLoaded >= 8) {
  43. initClouds();
  44. $('#headerCloudsContainer').removeClass('invisible');
  45. }
  46. }
  47.  
  48. var skyImage = new Image();
  49. skyImage.onload = imageLoaded
  50. skyImage.src = 'https://lorwolf.azureedge.net/static/Title Screen Sky.png';
  51.  
  52. var forgroundImage = new Image();
  53. forgroundImage.onload = imageLoaded
  54. forgroundImage.src = 'https://lorwolf.azureedge.net/layout/Title-Screen-Front.png';
  55.  
  56. var cloud1Loader = new Image();
  57. cloud1Loader.onload = function () {
  58.  
  59. imageLoaded();
  60. }
  61. cloud1Loader.src = cloud1.url;
  62.  
  63. var cloud1BehindLoader = new Image();
  64. cloud1BehindLoader.onload = function () {
  65.  
  66. imageLoaded();
  67. }
  68. cloud1BehindLoader.src = cloud1Behind.url;
  69.  
  70.  
  71.  
  72. var cloud2Loader = new Image();
  73. cloud2Loader.onload = function () {
  74.  
  75. imageLoaded();
  76. }
  77. cloud2Loader.src = cloud2.url;
  78.  
  79. var cloud2BehindLoader = new Image();
  80. cloud2BehindLoader.onload = function () {
  81.  
  82. imageLoaded();
  83. }
  84. cloud2BehindLoader.src = cloud2Behind.url;
  85.  
  86.  
  87.  
  88. var cloud3Loader = new Image();
  89. cloud3Loader.onload = function () {
  90.  
  91. imageLoaded();
  92. }
  93. cloud3Loader.src = cloud3.url;
  94.  
  95. var cloud3BehindLoader = new Image();
  96. cloud3BehindLoader.onload = function () {
  97.  
  98. imageLoaded();
  99. }
  100. cloud3BehindLoader.src = cloud3Behind.url;
  101.  
  102.  
  103. var canvas = document.getElementById('headerClouds');
  104. var stage = new createjs.Stage("headerClouds");
  105.  
  106. createjs.Ticker.setFPS(45);
  107.  
  108. var shapes = [];
  109. var shapeIndex = 0;
  110.  
  111. function addImage(url, x, y, width, height, alpha, alternateStage) {
  112. var stageToUpdate = stage;
  113. if (alternateStage) {
  114. stageToUpdate = alternateStage;
  115. }
  116. alpha = alpha || 1;
  117. var img = new Image();
  118. var shape = null;
  119. var currentShapeIndex = shapeIndex;
  120. shapeIndex++;
  121. img.onload = function () {
  122. shape = new createjs.Shape();
  123. shape.alpha = alpha;
  124. stageToUpdate.addChild(shape);
  125. shapes[currentShapeIndex] = shape;
  126. img.scaleY = height / img.height;
  127. img.scaleX = width / img.width;
  128. var m = new createjs.Matrix2D();
  129. m.translate(x, y);
  130. m.scale(width / img.width, height / img.height);
  131. shape.graphics.clear().beginBitmapFill(img, 'no-repeat', m);
  132. var fill = shape.graphics.drawRect(x, y, width, height).command;
  133.  
  134. shape.cache(x, y, fill.w, fill.h); // added
  135.  
  136. stageToUpdate.update();
  137. };
  138. img.src = url;
  139. return currentShapeIndex;
  140. }
  141.  
  142. function initClouds() {
  143.  
  144. var cloudSpeed = -.05; // -X pixels per frame
  145. var cloudBehindSpeed = -.1; // -X pixels per frame
  146. var cloudWidth = 2000;
  147.  
  148. function handleClouds() {
  149.  
  150. if (document.hidden)
  151. return; // tab is not active in browser
  152.  
  153. var currentScrollTop = $(window).scrollTop();
  154. var cloudsHeight = $('#headerClouds').height();
  155. if (currentScrollTop > cloudsHeight)
  156. return; // user is scrolled past the clouds
  157.  
  158. // cloud 1
  159. if (!cloud1.loaded) {
  160. cloud1.loaded = true;
  161. cloud1.shapeIndex = addImage(cloud1.url, 0, 0, cloudWidth, 300, 1, null);
  162. } else {
  163. if (shapes[cloud1.shapeIndex]) {
  164. shapes[cloud1.shapeIndex].x += cloudSpeed;
  165. if (cloud1.hasBeenMoved) {
  166. if (shapes[cloud1.shapeIndex].x <= -cloudWidth) {
  167. shapes[cloud1.shapeIndex].x = cloudWidth * 2;
  168. }
  169. } else {
  170. if (shapes[cloud1.shapeIndex].x <= -cloudWidth) {
  171. cloud1.hasBeenMoved = true;
  172. shapes[cloud1.shapeIndex].x = cloudWidth * 2;
  173. }
  174. }
  175. }
  176. }
  177.  
  178. // cloud 1 behind
  179. if (!cloud1Behind.loaded) {
  180. cloud1Behind.loaded = true;
  181. cloud1Behind.shapeIndex = addImage(cloud1Behind.url, 0, 0, cloudWidth, 300, 1, null);
  182. } else {
  183. if (shapes[cloud1Behind.shapeIndex]) {
  184. shapes[cloud1Behind.shapeIndex].x += cloudBehindSpeed;
  185. if (cloud1Behind.hasBeenMoved) {
  186. if (shapes[cloud1Behind.shapeIndex].x <= -cloudWidth) {
  187. shapes[cloud1Behind.shapeIndex].x = cloudWidth * 2;
  188. }
  189. } else {
  190. if (shapes[cloud1Behind.shapeIndex].x <= -cloudWidth) {
  191. cloud1Behind.hasBeenMoved = true;
  192. shapes[cloud1Behind.shapeIndex].x = cloudWidth * 2;
  193. }
  194. }
  195. }
  196. }
  197.  
  198. // cloud 2
  199. if (!cloud2.loaded) {
  200. cloud2.loaded = true;
  201. cloud2.shapeIndex = addImage(cloud2.url, cloudWidth, 0, cloudWidth, 300, 1, null);
  202. } else {
  203. if (shapes[cloud2.shapeIndex]) {
  204. shapes[cloud2.shapeIndex].x += cloudSpeed;
  205. if (cloud2.hasBeenMoved) {
  206. if (shapes[cloud2.shapeIndex].x <= -cloudWidth * 2) {
  207. shapes[cloud2.shapeIndex].x = cloudWidth;
  208. }
  209. } else {
  210. if (shapes[cloud2.shapeIndex].x <= -cloudWidth * 2) {
  211. cloud2.hasBeenMoved = true;
  212. shapes[cloud2.shapeIndex].x = cloudWidth;
  213. }
  214. }
  215. }
  216. }
  217.  
  218. // cloud 2 behind
  219. if (!cloud2Behind.loaded) {
  220. cloud2Behind.loaded = true;
  221. cloud2Behind.shapeIndex = addImage(cloud2Behind.url, cloudWidth, 0, cloudWidth, 300, 1, null);
  222. } else {
  223. if (shapes[cloud2Behind.shapeIndex]) {
  224. shapes[cloud2Behind.shapeIndex].x += cloudBehindSpeed;
  225. if (cloud2Behind.hasBeenMoved) {
  226. if (shapes[cloud2Behind.shapeIndex].x <= -cloudWidth * 2) {
  227. shapes[cloud2Behind.shapeIndex].x = cloudWidth;
  228. }
  229. } else {
  230. if (shapes[cloud2Behind.shapeIndex].x <= -cloudWidth * 2) {
  231. cloud2Behind.hasBeenMoved = true;
  232. shapes[cloud2Behind.shapeIndex].x = cloudWidth;
  233. }
  234. }
  235. }
  236. }
  237.  
  238. // cloud 3
  239. if (!cloud3.loaded) {
  240. cloud3.loaded = true;
  241. cloud3.shapeIndex = addImage(cloud3.url, cloudWidth * 2, 0, cloudWidth, 300, 1, null);
  242. } else {
  243. if (shapes[cloud3.shapeIndex]) {
  244. shapes[cloud3.shapeIndex].x += cloudSpeed;
  245. if (cloud3.hasBeenMoved) {
  246. if (shapes[cloud3.shapeIndex].x <= -cloudWidth * 3) {
  247. shapes[cloud3.shapeIndex].x = 0;
  248. }
  249. } else {
  250. if (shapes[cloud3.shapeIndex].x <= -cloudWidth * 3) {
  251. cloud3.hasBeenMoved = true;
  252. shapes[cloud3.shapeIndex].x = 0;
  253. }
  254. }
  255. }
  256. }
  257.  
  258. // cloud 3 behind
  259. if (!cloud3Behind.loaded) {
  260. cloud3Behind.loaded = true;
  261. cloud3Behind.shapeIndex = addImage(cloud3Behind.url, cloudWidth * 2, 0, cloudWidth, 300, 1, null);
  262. } else {
  263. if (shapes[cloud3Behind.shapeIndex]) {
  264. shapes[cloud3Behind.shapeIndex].x += cloudBehindSpeed;
  265. if (cloud3Behind.hasBeenMoved) {
  266. if (shapes[cloud3Behind.shapeIndex].x <= -cloudWidth * 3) {
  267. shapes[cloud3Behind.shapeIndex].x = 0;
  268. }
  269. } else {
  270. if (shapes[cloud3Behind.shapeIndex].x <= -cloudWidth * 3) {
  271. cloud3Behind.hasBeenMoved = true;
  272. shapes[cloud3Behind.shapeIndex].x = 0;
  273. }
  274. }
  275. }
  276. }
  277.  
  278. stage.update();
  279. }
  280.  
  281. createjs.Ticker.addEventListener("tick", handleClouds);
  282.  
  283. }
  284. }
  285.  
  286. function initCloudsIfApplicable() {
  287. if (!cloundsInitialized) {
  288. if (!isMobile() && !isTablet() && !$("html").hasClass("darkMode")) {
  289. initHeaderClouds();
  290. cloundsInitialized = true;
  291. }
  292. }
  293. }
  294.  
  295. initCloudsIfApplicable();
  296. $(window).resize(initCloudsIfApplicable);
  297.  
  298. })
  299.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement