Search Unity

2D Toolkit - 2D in Unity made simple [RELEASED]

Discussion in 'Assets and Asset Store' started by unikronsoftware, Jun 16, 2011.

  1. EskemaGames

    EskemaGames

    Joined:
    Jun 23, 2010
    Posts:
    319
    Does this package have features for joysticks?, it's cool to create a 2d game, but I don't see anything on the docs regarding a joystick component, different buttons, panels, etc,etc.
    Can this tool be also used for all the GUI needs?
     
  2. Bezzy

    Bezzy

    Joined:
    Apr 1, 2009
    Posts:
    75
    It's cool. Just glad I caught it early.

    Changed the default in source to "Unset" rather than "None".

    Had to hand-set 40 frames, but no biggy - like I say, caught it early. Thanks man!
     
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There isn't a feature for joysticks, but you can use the one built in to Unity for that. As for GUI, we are waiting for Unity 3.5 to be released before deciding whether to include a full GUI solution, as there is going to be an update for GUI in that version. For now, we only provide a button script, but it should be easy enough to customise to your requirements.

    unikron
     
  4. Gopher42

    Gopher42

    Joined:
    Oct 19, 2011
    Posts:
    30
    Just bought this plugin yesterday, quite happy with it so far, but I've run into an issue.

    In my project, I've got one logical object that switches between two different prefabs, similar to the way you might switch a player prefab for a ragdoll. Completely different sets of behaviors for the two, but they use the same animated sprites.

    Until yesterday I was using primitives - cubes and spheres - to represent objects, and there are quite a few properties I've been copying over right after calling Instantiate. All of these were being applied in time for the next frame, making the transition completely seamless. However, when calling Play() on the animation, to synchronize it to the current animation it is replacing, is taking an extra update to be applied.

    Basically, for the first rendered frame in which the new object and it's sprite exist, it is always using the animation or frame specified on the prefab. The animation I specify in the call to Play() right after Instantiate is not "kicking in" until the 2nd frame, leaving this one frame twitch where the object is not rotated correctly. I've tried everything I can think of, but nothing is working.

    Now, I know I could fix this by making a separate prefab for all 8 possible directions, and dynamically identifying and selecting the right one on the fly - but this seems mad, to make 8 prefabs just to change one setting! And later, I was planning on adding 2 more states for each of the 8 rotations, making 24 prefabs... and after THAT, I was planning on having half a dozen variations of the same object with the different sets of these sprites, bringing the total permutations of prefabs I'd have to create up to 144!

    Surely there's a better way that I'm missing?

    :edit:
    So I set up a simple project that shows what I'm talking about.

    Made a simple project, one scene and two prefabs. Made the prefabs use red and blue sprites, so just to distinguish them.
    Web Build
    Download project .zip (requires tk2d, obviously)

    controls: arrows move the block around.
    left-Control or left-click will cause it to flip between the horizontal and vertical rect sprites
    left-shift or middle-click will cause it to instantiate the other type, copying it's position and sprite state

    The prefabs are both set to the horiz. rect sprite, and everything seems fine switching between those. Toggle to the vertical and then switch, though, and you get the one frame flicker of the wrong sprite. Notice that the transform data is applied in the first frame, only the animation does not.
     
    Last edited: Nov 15, 2011
  5. trickster

    trickster

    Joined:
    May 18, 2009
    Posts:
    1
    Hi,

    Just getting started with your 2d toolkit but am a little confused with some of the documentation. What's the purpose of the animation delegate exactly? As far as sprite animation commands, is there a list of all the functions and parameters accessible through scripting? Is there a way thru scripting to have an animation play to a certain frame number, pause, and then based on user input continue to play? Could I play the animation in reverse thru scripting or do I set up a separate animation for that using the same sprites? Also, could you include audio in your tutorial videos. I think it will go a long way to explain the material better.

    Thank you for your product by the way, it looks to be the best one on the market right now.
     
  6. MrScary

    MrScary

    Joined:
    Dec 8, 2007
    Posts:
    94
    Is anyone else seeing this when doing iphone builds?

    Code (csharp):
    1. Instance of tk2dSpriteCollectionEditor couldn't be created because there is no script with that name.
    2. UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
    3.  
    I just updated to the latest and this started happening. Doesn't prevent my iphone build and xcode from loading the project, but it's annoying seeing an "error" in the console output.
     
  7. stromdotcom

    stromdotcom

    Joined:
    May 22, 2011
    Posts:
    3
    I have a question that is only slightly related to 2D Toolkit I think, hopefully someone can help me.

    If I have a sprite in my scene, just a rectangle, say centered at x,y and with width w and height h, how can I get the world coordinates of each corner of the sprite?

    I need to take those coordinates and convert to screen coords in order to do a screen capture, but I can't for the life of me figure out how to determine where those coordinates are. Or even how to get the width and height of the rectangle so I can just subtract from the center point.
     
  8. Gopher42

    Gopher42

    Joined:
    Oct 19, 2011
    Posts:
    30
    Found a solution to my problem: disabled the MeshRenderer component on both of the prefabs, and start a coroutine from update that does the actual swapping as follows: Instantiate the new one, play, yield, enable renderer, destroy self. Works smoothly, but still feels like a work-around more than a real solution. Is also going to require me to tweak my objects not to do anything during the next update which could cause problems, since they are supposed be dead at that point, so it's less than ideal. Is there a technical reason I'm just not seeing for one-frame delay in starting a new animation after play is called?
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You shouldn't really have to do that - it sounds like a massively complicated workaround to something which should be very simple.

    With regards to the one frame delay, where are you calling play from? The script order in Unity is generally undefined, unless you explicitly set it up - you can set this up in Edit > Project Settings > Script Execution Order. Basically whats happening is the Update function you're calling Play from, is executing AFTER the animated sprite update function, which in turn means you only see the update on the next frame when the animated sprite updates it. By making the animated sprite update last in the script execution order, you'll ensure Update gets called at the right point.

    Cheers,
    unikron
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can get the world coordinate of the center of the sprite by calling transform.position. If all you care about is the rectangular screen bounds, you can simply grab renderer.bounds and use that to evaluate each corner.

    If you need very precise bounds, you should make tk2dBaseSprite.GetBounds public, and call that - that will give you local bounds, which you can then transform into world space using your transform component.

    unikron
     
  11. Gopher42

    Gopher42

    Joined:
    Oct 19, 2011
    Posts:
    30
    unikron, the web build showing what I'm talking about is still hosted, as is the zip containing the project that includes it. Since I'm calling instantiate on one line and calling play on the next, I'm not sure there's much else I could do in terms of order of execution.

    I'm fairly new to unity - just ran out my free month and paid for iOS basic yesterday - so it's possible there's something I'm just not getting here and doing wrong, but the sample case is so simple, I can't imagine what.
     
    Last edited: Nov 16, 2011
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Actually, the script execution order will still make a difference - assuming you call Instantiate and Play from Update in a script called GameController - if GameController executes after tk2dAnimatedSprite.Update, it will only end up updating on the next frame.

    Hope that makes sense - my internet connection is acting up, its taking far too long to download your files, I'll update this again when I have seen it.

    If this doesn't work, you can also call tk2dAnimatedSprite.SetFrame(0) right after calling Play to force it to update immediately. You will need to make that function public, but it should work fine. This is a bit of a hack though, so try to avoid it if you can.
     
  13. Gopher42

    Gopher42

    Joined:
    Oct 19, 2011
    Posts:
    30
    update can't have been called yet on the sprite. The sprite is on the prefab being instantiated. Might try the SetFrame() trick tomorrow, though, thanks.
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    There are 2 animation delegates supported,
    animationCompleteDelegate fires when the animation has completed playing
    animationEventDelegate is set up in the interface to trigger when playing certain frames of animation.

    About the sprite animation commands - it looks like that part of the docs never made it to the wiki. You can still find them in the pdf docs distributed with the project.

    You can't make the animation play to a certain frame, pause, etc. straight out of the box, but you can do that with the animationEventDelegate. Basically you set it up so a trigger is fired on the frame you're interested in, and then call Pause from within your delegate. At this point, you can call Resume whenever you get the input you're interested in.

    There isn't a function to play in reverse, but you can really quickly reverse an animation by clicking on the Reverse button in the interface. Alternatively you can modify tk2dAnimatedSprite to do this in script - it should be really straightforward. There have been a few requests for Reverse so far, so I'll probably get that implemented in the next version.

    We are always looking to improve documentation and tutorials - the last batch we did were the ones on the wiki. We are looking into improve the video ones later. Thanks for the feedback.

    unikron
     
  15. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, I do get that as well. No idea whats causing it now, I will investigate this after the next version has been released.

    Cheers,
    unikron
     
  16. zhaoling23

    zhaoling23

    Joined:
    Nov 16, 2011
    Posts:
    1
    If I have an atlas which is about a human character storing a sequence of frames, I would like to know if 2D toolkit is able to build colliders in one frame and animate it in all other frames?

    That is, can I construct the collider with editor in 2D toolkit for the character (acturally a .png picture) and animate the collider automatically in all other frames?
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    As mentioned in the email, you can automatically create a best fit box collider - you can do this automatically for all your frames. You can then go in and edit them if necessary.
     
  18. dead1ock

    dead1ock

    Joined:
    Jan 4, 2011
    Posts:
    31
    Is it possible to get to the Character Controller to work with a sprite? Whenever I try to add it, it wants me to replace the box collider and when I do replace the box collider it gets regenerated and causes the rigidbody to not work properly (the object stalls in mid-air) but when I remove the character controller everything returns to normal.

    Does anyone have a good 2d side scroller controller script? I've been fiddling with mine (which uses the rigidbody and forces) but I just can't get it working the way I want to.
     
  19. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    Hi,

    I have a scenario where I want to use materials and shaders for the game background and sprites via 2d toolkit for the foreground.

    Is there a suggested workflow to set up the camera and lighting for this type of game?

    Thanks,

    Kevin
     
  20. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    Hi,

    I'm developing an iPad title and was wondering what settings to use for the Orthographic camera. I'm getting conflicting reports on how to do this to set up 1:1 pixel perfect sprites.

    The current formula I use for a 1024 ( width ) x 768 ( height ) game is:
    ortho = 768/2 = 384

    So, I set me Orthographic camera size to 384 and set the camera location to -384.

    Is this necessary? In the 2d toolkit tutorial it mentions setting the Ortho size to 1.0. How does this affect the iPad screen size?
     
  21. raymondes

    raymondes

    Joined:
    Sep 17, 2011
    Posts:
    7
    Code (csharp):
    1. Instance of tk2dSpriteCollectionEditor couldn't be created. The script class needs to derive from ScriptableObject and be placed in the Assets/Editor folder.
    I get this error as soon as I try to make a sprite collection, and when the sprite collection is created there are no 'Commit' and 'Edit' buttons in the Inspector either..... I have the newest version of 2D Toolkit and Unity.

    Any help would be greatly appreciated!
     
  22. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    I had some performance issues, I had a huge performance drop each time I changed background.(It was 1024x1024). I had a thought that because it didn't always happen every time it must have happened when a new background changed into a different background it hadn't previously changed into.

    So I made a simple script that looped through ALL sprites before the scene began. I'm assuming because this worked the issue was with the large size of the background and there isn't a way around this other than to loop-through all possible backgrounds it will become?


    Argh, it helped with performance but there is still a huge drop when the background moves. Damn no parallax!

    EDIT: Nevermind, I noticed i was doing all that in my function in LateUpdate(), it's fixed now.
     
    Last edited: Nov 19, 2011
  23. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,

    Do you need to be able to index the positions on screen by pixel positions, then this is OK. Otherwise, simply use any sensible value. 1 is fine for most cases, 10 or 100 is better when you use physics, and want to use default settings. This size simply affects the coordinate space, and doesn't have anything to do with the resolution of the screen.

    For the camera height, use 768 if in landscape and 1024 if portrait. This value should directly correspond to the height of the screen.

    unikron
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,

    You will need to disable the automatic material generation in tk2dSpriteCollectionBuilder so 2d toolkit doesn't keep regenerating the material, but apart fro that, you can set it up to use any material you like. If you need lighting, you need to create normals and tangents. You can use any kind of lighting you like with it.

    unikron
     
  25. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is strange. Is your TK2DROOT folder in the root of your project? Or has it been moved elsewhere? This usually happens when the script can't be found - i.e. its been moved into plugins.
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We've used the character controller, but not with box colliders. We simply, use the character controller - that uses a cylinder I believe, and that works fine. Sorry, we don't have a side scroller script which we can share, it was done for a client - hopefully someone else who has done this will be able to help here.
     
  27. ssfulfer

    ssfulfer

    Joined:
    Jan 26, 2011
    Posts:
    6
    Looking into getting this tool or ex2d to help with 2d games. One thing that would help me decide is what the roadmap is for this tool. With ex2d I have at least some idea of where they are going. Is there anything you can share about the 2dToolkit roadmap?

    - Steven
     
  28. dead1ock

    dead1ock

    Joined:
    Jan 4, 2011
    Posts:
    31
    Ditto.
     
  29. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We've not got a full long term roadmap per se, as we are deciding that based on demand, requests and our own needs - however we do have fairly concrete plans for the next 2 major versions. The next version will include a Tilemap editor, and the version after that will be for seamless multi resolution support. This is in addition to the usual bug fixes and smaller feature requests.
     
  30. ssfulfer

    ssfulfer

    Joined:
    Jan 26, 2011
    Posts:
    6
    Hi Unikron,

    Thanks for the reply. Any thoughts on improving the animation editor to have things like a previewer? Any plan for scale9grid capabilities?

    -Steven
     
  31. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    "seamless multi resolution support"
    +1 to this!
     
  32. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    Is there any way within the 2d toolkit to define a clipping rectangle for a sprite (or set of sprites)?

    My goal is to display the sprites only when within a certain rectangle. The current solution is to overlay other sprites and use Unity's built-in culling by depth.

    Kevin
     
  33. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    I have a question regarding external sprite sheet animations for tk2dSpriteCollections.

    So, I see that there's a really quick and intuitive way to create animations from an externally generated sprite sheet if:

    1) The sprites are all fixed width (eg, all animation frames are 64x64 with no attempt to pack the sprites)
    2) The sprites are arranged such that their cycles stretch horizontally from 0,0 to N,0 and then 0,1 to N,1.

    But doing this doesn't give you the same friendly naming that you get from importing a million little sprite pngs separately.


    *Question* : Is it possible to use a texture packed sprite sheet, for example from Texture Packer, and also supply a pList? If so, is there a tutorial on how to do this? I haven't found one yet.
     
  34. bryanleister

    bryanleister

    Joined:
    Apr 28, 2009
    Posts:
    130
    I apologize if this has been asked before, but it's not that easy to search just in this thread.

    Is it possible to Animate the alpha channel of a static Sprite using Unity's built-in animation editor? I can see that I am allowed to set frames on the Color.a 2dtk script and the values animate, but the sprite does not change.

    What I am trying to do is fade-in some sprites for a user interface. It would also be nice if I could animate the Sprites color as well.
     
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,

    There have been requests for a new animation editor, so that is in the pipeline - just the other 2 features I mentioned have been requested far more!

    For the scale9grid thing - we have planned something far more flexible than that (for use in game, not GUI). Unity 3.5 should include the new GUI stuff, so we're not really concentrating on GUI specific features all that much. However, this thing we have planned will work with scale9 as well as the cool stuff for beams, lightning and other fx in game.

    Cheers,
    unikron
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No, this isn't possible, as you can't animate properties, just values. We do this on one of our projects though - we created a derived tk2dSprite class which has an update function which polls and sees if the color, etc have changed, and then change them. You don't want to do this globally as it will slow things down.

    Another method which we tend to favor now is to create a behaviour which has an event which fades the sprite in with a coroutine, then calling that from the animation editor with the appropriate parameters.

    Of course, you could still do a hybrid thing which does a bit of both.

     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'm looking into this for you - I believe there might be a much better way than to explicitly add clipping code.
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can actually go in and rename the sprites after they have been imported from a sprite sheet. Whether you want to do it when you have 100s of sprites is another matter entirely...

    You can't use a texture packed sprite sheet, but how important do you think this is? It will be trivial to add this as a feature, but obviously the additional data won't be tweakable like physics, etc.

     
  39. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    350
    Well, it's more a matter of whether we can take assets created for previous projects that might have been built to target platform N using language and toolchain X, and putting them into Unity using 2DToolKit so that we can target all of Unity's available platforms using C# only.

    It's not just about previous projects, though. External assets from 3rd parties often use Texture Packer as well. It's become somewhat of a standard in that respect. Also, some are doubtful of the long-term future of the Unity editor and platform and would prefer not to rely on Unity or its plugins to create packed textures, even though Unity is currently ascendant (Just ask the flash community how they feel about their assets existing in a once-dominant proprietary format, for which there is no transparent path for exporting to a more neutral format for example). That way, if the assets need to be re-used in a theoretical future in which Unity is no longer a viable tool at least the raw png assets are in a relatively platform agnostic format with a plain text plist.
     
  40. Koosmono

    Koosmono

    Joined:
    Nov 23, 2011
    Posts:
    1
    Hello all,

    I read through the documentation today and am now very interested in the 2D toolkit. I've had some success already with some free 2D kits, but am looking to throw down some cash for an upgrade and start making some serious 2D games.

    I would like to use JavaScript and the documentation makes that seem simple enough. However, I skimmed this thread and couldn't find much on JS, other then people having some pretty simple problems with it and the toolkit.

    So I just wanted to ask if there are people out there who have had success using 2Dtoolkit and JavaScript for their projects? If so I am very interested, as this tool looks amazing.

    Thanks for any help!
     
  41. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    -ignore-
     
    Last edited: Nov 24, 2011
  42. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    Not support Input label? I mean textfield
     
    Last edited: Nov 24, 2011
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No, not yet. This may be in a future release, but we are waiting for Unity 3.5 first.
     
  44. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Since no one has responded so far - it is possible to use 2D Toolkit with JS. You will need to perform the steps outlined in the FAQ on the Wiki (http://www.unikronsoftware.com/2dtoolkit/wiki/pmwiki.php/Main/Faqs). After that, you will be able to use all the features directly.
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Feedback taken on board - we will try and get a feature like this in a future release.

    Cheers,
    unikron

     
  46. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,

    There is a way to do this with multiple cameras and the normalised viewport rect to position the contents of the camera on screen. This should be much more efficient than manually clipping, especially with more complicated meshes. If you try this, don't forget to change the ortho size to compensate for the reduction in size... Also, don't forget to set the second camera to "Don't Clear".

    Drop me an email to support at unikronsoftware dot com if you'd like to discuss this further.

    Cheers,
    unikron
     
  47. Amon

    Amon

    Joined:
    Oct 18, 2009
    Posts:
    1,384
    I just bought this. Finding it awesome so far.
     
  48. lorenzo.cambiaghi

    lorenzo.cambiaghi

    Joined:
    Aug 16, 2011
    Posts:
    10
    The function "iTween.FadeTo(...." doesn't work because it can't find _Color property on shader.

    I tried:
    iTween.FadeTo(gameObject, iTween.Hash("alpha",0,"time",2, "delay",0, "includeChildren",true,"easetype","easeInOutSine","oncomplete","Remove"));
     
  49. Dabeh

    Dabeh

    Joined:
    Oct 26, 2011
    Posts:
    1,614
    Going to assume theres no _Color property on the shader then.
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There isn't a _Color property on the shader - we use vertex colours to tint the objects - using _Color means you will need a unique material (and draw call) for each object you want to fade and the performance of that can go horribly bad...

    If you want to, you can assign a material which has a _Color property, the sprites will still work there, this might work out well for you depending on your circumstances.
     
    Last edited: Nov 25, 2011