Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. // what I am doing is testing my logic. I had an idea... but it doesn't mean its going to fucking work. I need to make sure the system is creating an array like its suppose to.
  2. //now no matter what the value becomes an array. So once we do the loop/create its much easier to create the logic. You can tell its an array because its in square brackets.
  3. // so now you would want to clone this for all the other attributes. I am not going to do it just so I can get to array logic - You will have to fix other attributes.
  4. //lol now its not working in other direction..
  5. // worked in both directions. We are good. Lets just test no arrays just in case. It created the single array length like it was suppose to and looped still with a single object.
  6. // next you want to create a good naming for multiple sprites - also make it so when no array is detected it knows not to use a -# naming for sprie.. because someone doesn't want to usxe
  7. // sprite-1 if there is no sprite-1.. You can make an var in that check that I do that creats the array if there is no arrayLengths. So just add in the game logic and your other attributes.
  8. let spriteAttributes = {
  9. sprite1: {
  10. position: {
  11. x: 10,
  12. y: [25,55,555]
  13. }
  14. }
  15. }
  16.  
  17. let game;
  18.  
  19. var spriteCreation = function (spriteAttributes) {
  20.  
  21.  
  22.  
  23.  
  24. for (var key in Object.keys(spriteAttributes)) {
  25. var arrayLengths = new Array();
  26. spriteName = Object.keys(spriteAttributes)[key];
  27.  
  28.  
  29. if (spriteAttributes[spriteName].position.x) {
  30. if(!Array.isArray(spriteAttributes[spriteName].position.x)){
  31. spriteAttributes[spriteName].position.x = [spriteAttributes[spriteName].position.x];
  32.  
  33. arrayLengths.push(spriteAttributes[spriteName].position.x.length);
  34.  
  35. } else {
  36. spriteAttributes[spriteName].position.x = spriteAttributes[spriteName].position.x;
  37. arrayLengths.push(spriteAttributes[spriteName].position.x.length);
  38. }
  39. }
  40.  
  41. if (spriteAttributes[spriteName].position.y) {
  42. if(!Array.isArray(spriteAttributes[spriteName].position.y)){
  43. spriteAttributes[spriteName].position.y = [spriteAttributes[spriteName].position.y];
  44. arrayLengths.push(spriteAttributes[spriteName].position.y.length);
  45. } else {
  46. spriteAttributes[spriteName].position.y = spriteAttributes[spriteName].position.y;
  47. arrayLengths.push(spriteAttributes[spriteName].position.y.length);
  48. }
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. // game[spriteName] = game.add.sprite(spriteAttributes[spriteName].position.y, spriteAttributes[spriteName].position.y, spriteName);
  57.  
  58.  
  59. // //sprite anchor
  60. // if (!spriteAttributes[spriteName].anchor) {
  61. // spriteAttributes[spriteName].anchor = {};
  62. // }
  63. // if (!spriteAttributes[spriteName].anchor.x) {
  64. // spriteAttributes[spriteName].anchor.x = 0;
  65. // }
  66. // if (!spriteAttributes[spriteName].anchor.y) {
  67. // spriteAttributes[spriteName].anchor.y = 0;
  68. // }
  69. // //sprite scale
  70. // if (!spriteAttributes[spriteName].scale) {
  71. // spriteAttributes[spriteName].scale = {};
  72. // }
  73. // if (!spriteAttributes[spriteName].scale.x) {
  74. // spriteAttributes[spriteName].scale.x = 1;
  75.  
  76. // }
  77. // if (!spriteAttributes[spriteName].scale.y) {
  78. // spriteAttributes[spriteName].scale.y = 1;
  79. // }
  80. // //sprite pivoting
  81. // if (!spriteAttributes[spriteName].pivot) {
  82. // spriteAttributes[spriteName].pivot = {};
  83. // }
  84. // if (!spriteAttributes[spriteName].pivot.x) {
  85. // spriteAttributes[spriteName].pivot.x = 0;
  86.  
  87. // }
  88. // if (!spriteAttributes[spriteName].pivot.y) {
  89. // spriteAttributes[spriteName].pivot.y = 0;
  90. // }
  91. // //sprite rotation
  92. // if (!spriteAttributes[spriteName].rotation) {
  93. // spriteAttributes[spriteName].rotation = {};
  94. // }
  95. // if (!spriteAttributes[spriteName].rotation.x) {
  96. // spriteAttributes[spriteName].rotation.x = 0;
  97.  
  98. // }
  99. // if (!spriteAttributes[spriteName].rotation.y) {
  100. // spriteAttributes[spriteName].rotation.y = 0;
  101. // }
  102. // //sprite angle
  103. // if (!spriteAttributes[spriteName].angle) {
  104. // spriteAttributes[spriteName].angle = 0;
  105. // }
  106.  
  107. // game[sprite].position.x = spriteAttributes.position.x;
  108. // game[sprite].position.y = spriteAttributes.position.y;
  109. // game[sprite].anchor.x = spriteAttributes.anchor.x;
  110. // game[sprite].anchor.y = spriteAttributes.anchor.y;
  111. // game[sprite].scale.x = spriteAttributes.scale.x;
  112. // game[sprite].scale.y = spriteAttributes.scale.y;
  113. // game[sprite].pivot.x = spriteAttributes.pivot.x;
  114. // game[sprite].pivot.y = spriteAttributes.pivot.y;
  115. // // game[sprite].rotation.x = spriteAttributes.rotation.x;
  116. // // game[sprite].rotation.y = spriteAttributes.rotation.y;
  117. // game[sprite].angle = spriteAttributes.angle;
  118.  
  119. console.log(spriteAttributes)
  120.  
  121. // game[spriteName] = game.add.sprite(spriteAttributes[spriteName].position.y, spriteAttributes[spriteName].position.y, spriteName);
  122. //hhmmmmm i don't get why its not working ha We need to do a for loop not a foreach...
  123. // lol see even i can look over simple shit.. Just gotta figure it out with console log methods.
  124.  
  125. if(arrayLengths.length > 0){
  126. arrayLengths.sort(function(a, b){return b-a});
  127. console.log('FUCK' + arrayLengths)
  128.  
  129.  
  130. } else {
  131. arrayLengths.push('1');
  132. //here you want to create some var that the loop can check for and if it sees it.. It knows not to name the sprites sprite-1,etc.. You also have to crate that system.
  133. }
  134.  
  135.  
  136. // now its remebers the last position of X even though its not as big.. SDo if we add 2 it should work until last... lets test. You see how im testing this with nodemon and how easy it is.
  137. for (key = 0; key < arrayLengths[0]; key++) {
  138.  
  139. if(spriteAttributes[spriteName].position.x[key]){
  140. console.log(spriteAttributes[spriteName].position.x[key])
  141. lastPosX = spriteAttributes[spriteName].position.x[key];
  142. } else {
  143. console.log (lastPosX);
  144. }
  145. if(spriteAttributes[spriteName].position.y[key]){
  146. console.log(spriteAttributes[spriteName].position.y[key])
  147. lastPosY = spriteAttributes[spriteName].position.y[key];
  148. } else {
  149. console.log (lastPosY);
  150. }
  151.  
  152.  
  153. };
  154.  
  155.  
  156.  
  157. //console.log(test['position.x']);
  158.  
  159.  
  160.  
  161.  
  162.  
  163. };
  164.  
  165.  
  166. }
  167.  
  168. spriteCreation(spriteAttributes);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement