Unity Community


Page 66 of 68 FirstFirst ... 16566465666768 LastLast
Results 1,301 to 1,320 of 1342

  1. Posts
    84
    I do this for UI elements that have an on/off state. For example, a health heart that can be empty or full will have 2 frames in the default animation (found inside the Sprite Timeline window)

    //Health empty:
    packedSpriteComponent.SetCurrentFrameForAnimation( 0, 0);

    //Health full:
    packedSpriteComponent.SetCurrentFrameForAnimation( 0, 1);


  2. Location
    Marina, California
    Posts
    90

    Extremely fundamental question.

    Hi. I'm still new to SM2, and while I've done a bunch of stuff with it, there seems to be something -very- fundamental I'm just not understanding here.

    In the game editor window, (NOT in code) I create an object (call it "mySprite") and add in a packed sprite component. Dress it all up, build atlases... everything is good so far.

    There it is on the screen.

    What I don't get is how to call the basic, built-in object methods on it.

    I have a script that I've attached to the mySprite object. It's got functions in it, and one of them is supposed to hide or show the sprite.

    That's the SM2 "obj.Hide(boolean)" call. I see it there in the docs. (or I see "Just call obj.Hide..." with some other name like "sprite.Hide()" or "yourSprite.Hide()" in the docs.

    Yes, I get that obj = sprite = yourSprite. I understand variables and object names. (I've actually been coding for a while now.) I just don't understand HOW to get that obj/sprite/yourSprite so I can use it.

    I've tried
    Code:  
    1.         var obj : GameObject = GameObject.Find(mySprite);      
    2.         obj.GetComponent(PackedSprite).Hide(false);

    I thought would work, but that does nothing at all.

    So, obviously I was out sick on day two of kindergarten.

    What do I need, what exact code, to be able to call Hide(), or Delete() or Draw() or any of the hundreds of other SM2 calls....?

    In short, how do I get "obj." ?

    I'm sorry to be so dense, when this is so fundamental, and it's a minor miracle that I've made it as far as I have.

    Would someone take me by the hand, and explain this to me (or slap some sense into me) please?
    "Don't believe everything you think."


  3. Posts
    2,251
    No problem. This is actually an important concept for Unity in general, so you'll find that this will help you in many ways far beyond SM2 as well. Even though this is a link to an EZ GUI thread, the concepts are exactly the same:

    http://forum.anbsoft.com/viewtopic.php?f=9&t=1408

    That thread should explain what you're after. If not, let me know.


  4. Location
    Marina, California
    Posts
    90
    Yes! Of course! and Duh!

    OK: I feel silly.

    Thanks, Brady. (sheepish grin follows...)
    "Don't believe everything you think."


  5. Posts
    332
    Quote Originally Posted by Brady View Post
    No problem. This is actually an important concept for Unity in general, so you'll find that this will help you in many ways far beyond SM2 as well. Even though this is a link to an EZ GUI thread, the concepts are exactly the same:

    http://forum.anbsoft.com/viewtopic.php?f=9&t=1408

    That thread should explain what you're after. If not, let me know.

    Hi Brady

    I just have a quick question about the examples you give in this link. For the code:
    Code:  
    1. var healthBar : UIProgressBar;
    2.  
    3. function Start()
    4. {
    5.    healthBar = GetComponent("UIProgressBar");
    6.  
    7.    // Now do something with it:
    8.    healthBar.Value = 1; // 100% health
    9. }

    ... why can't you just use...

    Code:  
    1. healthBar.Value = 1;
    ... i.e removing the GetComponent part... I thought by having it declared in the variable with var healthBar : UIProgressBar; you are already doing so?

    Sorry if this is a silly/noobish questions. Whilst my programming skills are improving, there are still fine details i need to learn.
    Cheers


  6. Posts
    332
    //double post sorry//


  7. Posts
    2,251
    You can do it that way as long as you populate that public reference by dragging it onto it in the inspector, and that is what is shown in the first example. Just declaring it public, however, isn't enough - you have to then populate it with the reference you want via the inspector. But the purpose of the second example was to show that if you don't want to use the inspector, you can do it programmatically using GetComponent().


  8. Location
    Toronto, Canada
    Posts
    4,709
    Hi Brady,
    I want to use PlayAnim() but I am told that PlayAnim() is not a member of Unity GameObject.


    How do I assign a packedSprite to be seen by Unity?


  9. Posts
    2,251
    See the thread I referenced above.


  10. Location
    Toronto, Canada
    Posts
    4,709
    HI Brady,
    I tried this...
    Code:  
    1.         var packedSpriteData = other.GetComponent(PackedSprite);
    2.         packedSpriteData.other.PlayAnim("animName");

    but other, is "not a member of packed sprite"


    Sorry I know this seems trivial I would like an answer.
    Thanks


  11. Posts
    2,251
    You don't need ".other" in there. PlayAnim() is a member of PackedSprite (and therefore your "packedSpriteData" reference), but ".other" is your own variable/reference. The line should read:

    packedSpriteData.PlayAnim("animName");

    Also, note that you don't want to use GetComponent() every time you go to access the sprite. Instead, if you don't want to use the inspector to populate your reference, then use GetComponent() to populate it in Start(), and then save the reference for later use.


  12. Location
    Toronto, Canada
    Posts
    4,709
    d'oh!
    Right, thanks.

    I have got it working but it now says that it can not find the animation.


    the following is my code. I have the identical name in the SpriteTimeLine Editor for this packed sprite. Including caps. It matches in the inspector but again, it says that it can not find the animation.


    Code:  
    1. #pragma strict
    2. var dummyFace : GameObject;
    3. var animName : String;
    4.  
    5. function OnTriggerEnter (other : Collider)
    6. {   
    7.     if(other.tag == "dummy")
    8.     {   
    9.         var packedSpriteData = dummyFace.GetComponent(PackedSprite);
    10.         packedSpriteData.PlayAnim("animName");
    11.     }
    12. }


  13. Posts
    2,251
    I'm not sure. Perhaps there are one or more trailing spaces in the name? Try using the index of the animation instead - that's faster anyway.


  14. Location
    Toronto, Canada
    Posts
    4,709
    ok. great.

    Thanks.


  15. Posts
    1

    Best TimelineFX Export Settings to Use with SM2

    Quote Originally Posted by Brady View Post
    BTW, TimelineFX is so awesome (some of the best procedurally generated explosions I've seen) that I've decided to promote it as a great companion to SM2. You'll find a link to it at the bottom of the SM2 page (www.anbsoft.com/middleware/sm2). If you heard about it from me and decide to order TimelineFX, please use the link on the SM2 page to order so that I receive proper credit for the referral.
    Hi Brady,

    Being new to both SM2 and TimelineFX, I was wondering if you could send a quick guide/recommendation on how to best use TimelineFX with SM2. Specifically, what export options/format to use and if there are any other tips that would be helpful to make the importing of those animations smoother.

    Thanks!

    Ryan


  16. Posts
    2,251
    There's not much to it, really. In my opinion, the easiest workflow is to export the animations as a batch of individual frames (I don't have the precise steps to do that here in front of me, but as I recall it's pretty straight-forward). Then use a PackedSprite component for your sprite, create a new animation on that PackedSprite (see the video tutorials on the steps for doing this) and drag the exported frames onto the animation timeline. That's pretty much all there is to it. Just build your atlas and you're good to go.


  17. Location
    Toronto, Canada
    Posts
    4,709
    edit:
    I am trying to access the frame rate of a sprite so I can change it dynamiclly.

    However, when I use..
    Code:  
    1. packedSpriteData.SetFramerate(1);
    it does nothing.


    Here is my full code.
    Code:  
    1.     for (var i : int = 0; i < coinMemberLength; i++)
    2.     {
    3.         var coin : GameObject;
    4.         coin = Instantiate(coinPF, coinMemberPos[i], transform.rotation);
    5.         if(i == 0)
    6.         {  
    7.             var packedSpriteData = coin.GetComponent(PackedSprite);
    8.             packedSpriteData.SetFramerate(1);
    9.         }
    10.     }
    Last edited by renman3000; 05-16-2012 at 08:18 AM.


  18. Posts
    2,251
    I think the issue is that since you just instantiated the object, its Start() hasn't run yet, and so there's no chance an animation is playing yet. The framerate gets set when you start an animation, and then you can change it from there, but when you first run the animation, it gets set to the default that is set for that animation. So it's getting changed as soon as the animation begins to play. You need to either call Start() on the component explicitly, or wait a frame before setting the framerate.


  19. Location
    Toronto, Canada
    Posts
    4,709
    Great. Thank you.


  20. Posts
    1
    Hello,

    just wanted to let you guys know that I had to contact AnBSoft with a licensing problem I had after purchasing SM2 and received excellent help from Brady.

    Always good to know a middleware provider puts customers first, thought that's worth sharing.

    Cheers,

    Markus

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •