2
0

main.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function SpriteToy::create( %this )
  23. {
  24. // Set the sandbox drag mode availability.
  25. Sandbox.allowManipulation( pan );
  26. // Set the manipulation mode.
  27. Sandbox.useManipulation( pan );
  28. // Reset the toy.
  29. SpriteToy.reset();
  30. }
  31. //-----------------------------------------------------------------------------
  32. function SpriteToy::destroy( %this )
  33. {
  34. }
  35. //-----------------------------------------------------------------------------
  36. function SpriteToy::reset( %this )
  37. {
  38. // Clear the scene.
  39. SandboxScene.clear();
  40. // Create background.
  41. %this.createBackground();
  42. // Create a "static" sprite.
  43. %this.createStaticSprite();
  44. // Create a "animated" sprite.
  45. %this.createAnimatedSprite();
  46. }
  47. //-----------------------------------------------------------------------------
  48. function SpriteToy::createBackground( %this )
  49. {
  50. // Create the sprite.
  51. %object = new Sprite();
  52. // Set the sprite as "static" so it is not affected by gravity.
  53. %object.setBodyType( static );
  54. // Always try to configure a scene-object prior to adding it to a scene for best performance.
  55. // Set the position.
  56. %object.Position = "0 0";
  57. // Set the size.
  58. %object.Size = "100 75";
  59. // Set to the furthest background layer.
  60. %object.SceneLayer = 31;
  61. // Set the scroller to use an animation!
  62. %object.Image = "ToyAssets:highlightBackground";
  63. // Set the blend color.
  64. %object.BlendColor = SlateGray;
  65. // Add the sprite to the scene.
  66. SandboxScene.add( %object );
  67. }
  68. //-----------------------------------------------------------------------------
  69. function SpriteToy::createStaticSprite( %this )
  70. {
  71. // Create the sprite.
  72. %object = new Sprite();
  73. // Always try to configure a scene-object prior to adding it to a scene for best performance.
  74. // Set the position.
  75. %object.Position = "-25 0";
  76. // If the size is to be square then we can simply pass a single value.
  77. // This applies to any 'Vector2' engine type.
  78. %object.Size = 40;
  79. // Set the sprite to use an image. This is known as "static" image mode.
  80. %object.Image = "ToyAssets:Tiles";
  81. // We don't really need to do this as the frame is set to zero by default.
  82. %object.Frame = 0;
  83. // Add the sprite to the scene.
  84. SandboxScene.add( %object );
  85. }
  86. //-----------------------------------------------------------------------------
  87. function SpriteToy::createAnimatedSprite( %this )
  88. {
  89. // Create the sprite.
  90. %object = new Sprite();
  91. // Always try to configure a scene-object prior to adding it to a scene for best performance.
  92. // Set the position.
  93. %object.Position = "25 0";
  94. // If the size is to be square then we can simply pass a single value.
  95. // This applies to any 'Vector2' engine type.
  96. %object.Size = 40;
  97. // Set the sprite to use an animation. This is known as "animated" image mode.
  98. %object.Animation = "ToyAssets:TileAnimation";
  99. // Add the sprite to the scene.
  100. SandboxScene.add( %object );
  101. }