Anim-complete delegates
Sometimes you may find that your game code needs to be notified when an animation is finished running. This is where you want to use an AnimCompleteDelegate. This is basically a function you write that you tell a sprite to call when any of its animations are finished playing. Below is a sample snippet of code to demonstrate how this is used.
// Tell the sprite to call MyDelegate() whenever
// Tell the sprite to call MyDelegate() whenever
|
Resized delegates
Sometimes it is useful to know when the dimensions of your sprite have been resized, such as if you want to resize its collider, etc. This is where you want to use an SpriteResizedDelegate. This is basically a function you write that you tell a sprite to call when it gets resized as a result of playing an animation frame that has a different width/height from the previous one. Below is a sample snippet of code to demonstrate how this is used.
// Tell the sprite to call MyDelegate() whenever
// Tell the sprite to call MyDelegate() whenever
|
Per-frame delegates
Sometimes you may want your code to be notified every time a sprite displays a new frame of animation. For example, if you want a sound to play on a specific frame. This is where you want to use an AnimFrameDelegate. This is basically a function you write that you tell a sprite to call every time it changes frames in an animation. Before you can make use of this type of delegate, you must first uncomment a line in one of the SpriteManager 2 scripts. The reason is that there is a small overhead for checking to call a per-frame delegate, and so this has been disabled by default. To enable this feature, uncomment the following line at the top of Sprite.cs (if using the Sprite class) or AutoSpriteBase.cs (if using PackedSprites): #define SPRITE_FRAME_DELEGATE Below is a sample snippet of code to demonstrate how this is used. // Tell the sprite to call MyDelegate() whenever
// Tell the sprite to call MyDelegate() whenever
|
Animation Pump Interval
By default, the SpriteAnimationPump ticks every frame. However, you can have it only run every so many seconds (or fraction of a second) by commenting out the following line in SpriteAnimationPump.cs: #define PUMP_EVERY_FRAME This will cause the animationPumpInterval to be used. The animationPumpInterval value controls the rate at which the animation coroutine runs for all sprites. The rate stored in animationPumpInterval is given in seconds. The default value is 0.03333 (30 frames per second), but can be changed at run-time, or simply modified in the sourcecode for SpriteAnimationPump. Increasing this value can lead to a significant improvement in performance when using large numbers of sprites (usually 100 or more on the iPhone), but can also degrade the apparent smoothness of your animations, depending on how high of a framerate you are using for your animations. If performance or appearance isn't satisfactory with the default value, try playing with it until you get what you are looking for. But in most cases, the default value should work well. |
Use Time.deltaTime
By design, the SpriteAnimationPump uses the real time passed in your game to animate sprites. This is so that you can still use animated sprites, and the like, in your pause menu (when Time.timeScale is set to 0). However, if you want setting Time.timeScale = 0 to pause your sprite animations as well, uncomment the following line at the top of SpriteAnimationPump.cs: #define USE_DELTA_TIME |
Screen Placement
The EZScreenPlacement component (found in the Components menu under EZ GUI->Utility->EZ Screen Placement) provides a way to position objects in the scene in a manner that is independent of screen resolution or aspect ratio. EZScreenPlacement allows you to specify that an object (including a non-SM2 object) should be placed in the scene either relative to one of the screen's edges, the screen center, or relative to another object in the scene. The distances from each of these frames of reference are given in pixel units. For example, you can tell an object to position itself 10 pixels from the left edge of the screen, and 10 pixels down from the top of the screen, regardless of resolution or aspect ratio. NOTE: For performance reasons, this component does not update every frame, so if the resolution changes, or an object moves that is set as the "Relative Object", the EZScreenPlacement component will not automatically update the object's position. If one of these events occurs, or for any other reason you want the object to recompute its position on-screen, simply call the component's PositionOnScreen() method, or its SetCamera() method. In addition to these, if SetCamera() is called on a sprite-based object, any attached EZScreenPlacement component will automatically be called as well.
|