Search Unity

Orthello 2D Framework - 100% FREE

Discussion in 'Assets and Asset Store' started by mas, Jul 7, 2011.

  1. ishaq

    ishaq

    Joined:
    Nov 12, 2008
    Posts:
    33
    this will come in handy when one has mirror frames for another pairing object e.g. a particular animation frames for right arm can be flipped to create animation for left arm. (flipping the left arm sprite would flip all the animations, which may be not what the developer wants).
     
  2. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Well I found myself, after some tries..

    Code (csharp):
    1.  
    2. GameObject atlasPrototype = new GameObject("AtlasCocos2DFnt");
    3. atlasPrototype.AddComponent<OTSpriteAtlasCocos2DFnt>().name = "AtlasCocos2DFnt";
    4.  
    5. OTSpriteAtlasCocos2DFnt atlas = (Instantiate(atlasPrototype) as GameObject).GetComponent<OTSpriteAtlasCocos2DFnt>();
    6. atlas.name = "Atlas_TimesNewRoman_44px";
    7. atlas.texture = Resources.Load("Fonts/BM_TimesNewRoman_44px") as Texture;
    8. atlas.atlasDataFile = Resources.Load("Fonts/ATLAS_TimesNewRoman_44px") as TextAsset;
    9.  
    Due to I'm not so experienced in Unity I don't know if this is the correct way, but it works.
     
    Last edited: Oct 3, 2013
  3. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    There is more than 1 way to achieve it! And you found one ... nicely done!
     
  4. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696

    If the arm is the only thing that is animating , you can use sprite.flipHorizontal to create the flipped sprite.
    I do not see any use case where this would not work if the arms are seperate sprites.
     
  5. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    The animation and sheets/atlasses can be added as a prefab by code as well. If you prepared the prefabs, by setting them up using configured Orthello objects, Orthello will remember the original names that were used and will try to do a 'late bind' using name lookup.

    So ...

    If you have correctly setup those prefabs, creating them using OT.CreateSprite, or OT.CreateObject ( for animations and atlasses ) would be very possible.
     
  6. FrederikBolding

    FrederikBolding

    Joined:
    Jul 6, 2012
    Posts:
    8

    1. OTSprite.image = something, doesn't change the sprite while the game is running

    2. 2 sprites are colliding and for some reason the collision isn't triggering (i can send you the game files if you wanna check it out)

    3. Okay!
     
    Last edited: Oct 5, 2013
  7. CrossRiverGames

    CrossRiverGames

    Joined:
    Jul 8, 2013
    Posts:
    15
    I have two questions here.

    First, I am trying to detect if there are any sprites under the sprite I am trying to instantiate. If there are, I want the instantiation process to stop. However, I can't seem to get the detection process coded correctly. All of the sprites in question are either OTSprite or OTAnimatingSprite, and they all have X and Y size values of 111 in their sprite properties. Here is the code that is not working:

    Code (csharp):
    1.         Vector2 position = new Vector2(xCoord,yCoord);
    2.        
    3.         // Check for obstacles/player
    4.         OTObject obstacleCheck;
    5.         Vector2 checkPosition = new Vector2(xCoord,yCoord);
    6.         obstacleCheck = OT.ObjectUnderPoint(checkPosition);
    7.         if(obstacleCheck != null)
    8.             return;
    9.         checkPosition.x = checkPosition.x + 111f;
    10.         obstacleCheck = OT.ObjectUnderPoint(checkPosition);
    11.         if(obstacleCheck != null)
    12.             return;
    13.         checkPosition.y = checkPosition.y + 111f;
    14.         obstacleCheck = OT.ObjectUnderPoint(checkPosition);
    15.         if(obstacleCheck != null)
    16.             return;
    17.         checkPosition.x = checkPosition.x - 111f;
    18.         obstacleCheck = OT.ObjectUnderPoint(checkPosition);
    19.         if(obstacleCheck != null)
    20.             return;
    21.  
    After this point in the code, the instantiation takes place. xCoord and yCoord are the given coordinates for the instantiation.


    My second question is this: If a sprite gets a certain distance above the player in the y-direction, I want to destroy it - but only if it has a certain tag. Is this possible? If so, how do I do it?

    Thanks for the help!
     
  8. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    1. mmm.. that would be a bug than because it should.

    2. please create a package of your project and send it over to us using info at wyrmtale dot com.
    also include instruction how to reproduce the error so we can try and solve it for you.
     
  9. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Your code looks solid and should work.

    Are you sure that all sprites have a collider, because I believe that is used to find the sprites under a specific point using ObjectUnderPoint. so .. make sure all sprites have sprite.registerInput set to true.


    To destroy that sprite ...

    a possible solution would be to create a custom script that checks the vertical position relative to the player in each update cycle and call OT.DestroyObject(sprite) when the sprite.gameObject.tag is the one you dislike!

    Hope this helps.
     
  10. FrederikBolding

    FrederikBolding

    Joined:
    Jul 6, 2012
    Posts:
    8
    Sent you an email :D
     
  11. CrossRiverGames

    CrossRiverGames

    Joined:
    Jul 8, 2013
    Posts:
    15
    All of the sprites in question have box colliders that I have tested (by colliding into them with the player sprite) and confirmed to work. The problem is that, for some reason, the sprites are instantiating on top of one another. They initially had their Register Input property set to false; I set it to true but that did not help.
     
  12. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Than let me take a look :

    please make a package with a setup that demonstrates your problem , put in some instructions on how to reproduce and send it over to info at wyrmtale dot com.
     
  13. bondoleg

    bondoleg

    Joined:
    Oct 6, 2013
    Posts:
    2
    I set some value for OTSprite.frameIndex in editor, but after every save/play it is set to 0. Why ? And how can i stop this ?
     
  14. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Where do you set the frameIndex? On a prefab in your project? on a sprite in your scene? is there an atlas linked?
     
  15. bondoleg

    bondoleg

    Joined:
    Oct 6, 2013
    Posts:
    2
    On a sprite in scene, with linked atlas.
     
  16. t3d-planet

    t3d-planet

    Joined:
    Apr 26, 2013
    Posts:
    11
    Hi,at first i would like to thank you for this great 2d framework , i found it so easy to use but may i ask if it is suitable to create Gui stuff like icons and Gui buttons and in game menu with it or should i use another solution for this task .
     
  17. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Yes ..

    I created the Orthello 2D Elements, Orthello 2D Form Elements and Orthello 2D Chart Elements as a layer ontop of the Orthello 100% free edition, so you easily could do this yourself with some good coding.

    .... or you could buy an elements pack and extend/adjust it ofc... ;)
    ( orthello elements has a menu and button example )
     
    Last edited: Oct 7, 2013
  18. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Is this on all your sprites or just on a specific one .. maybe you can try and recreate the sprite, because setting a sprite.frameIndex or sprite.frameName, is such basic Orthello functionality and there are no known issues with it.
     
  19. bodsey

    bodsey

    Joined:
    Oct 7, 2013
    Posts:
    6
    Hi !
    Thanks for this great plug-in

    I ran into perf issues when instantiating 25+ objects at the same time and I was starting to wondering if I didn't do things wrong. I was adding scripts in addition of OTSprite on objects, and as the plugin seems to optimize things with OTSprite, I wanted to make my scripts extends OTSprite instead.
    So I tried and did this and it bugged. When I moved my object in the editor, new objects were created in the editor ! Weird.

    So my question is, what's the best pipeline when scripting ? Extending OTSprite or adding a second script on the object ? If extending OTSprite is recommended, how would you do that ?

    Thanks !
     
  20. t3d-planet

    t3d-planet

    Joined:
    Apr 26, 2013
    Posts:
    11
    nice to hear that, and by looking to these packages i see it is achievable,thanks for your quick answer.
     
  21. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Extending is possible but takes very smart and advanced coding, as non documented info on what to override and what not. I cant seem to find that todo anywhere on my todo list!

    so best (and regular) way would be to add you own custom class to the sprite object.
     
  22. MasterSubby

    MasterSubby

    Joined:
    Sep 5, 2012
    Posts:
    252
    What would the property name, or how would you go about tweening one position only? I have a character moving along X constantly, and need to only update the Y position.
     
  23. Korenn

    Korenn

    Joined:
    Mar 18, 2013
    Posts:
    6
    Hello!

    Even though you completely ignored my last problem, I'll try again with a different one ;-)

    What do I need to do to update a TextSprite's text content after creating it? If I change the text directly after initialising, everything works as expected. But after that I can see in the editor that the OTTextSprite script is turned off, and setting the text to something else doesn't actually update the mesh (which makes sense). How do get it to update itself?

    EDIT: Solved on my own: just enable the monobehaviour with .enabled=true after updating any properties. I just made .text a property with a setter that does this automatically :D
     
    Last edited: Oct 10, 2013
  24. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Because the sprite.position can only be set as a Vector2 you will need to tween the entire vector. Another approach would be to create a custom script with some custom parameter like public custom.yPosition.

    You could than tween this custom yPosition property and adjust your sprite's position programmaticly in the yPosition's setter.

    Hope this makes sense....
     
  25. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Totally missed that previous post from 3 weeks ago .. sorry for that .. assume you got that yourself aswell..

    A better solution would be to call textSprite.ForceUpdate(); so only one update cycle is used and your cpu consumption is minimal.
     
  26. Korenn

    Korenn

    Joined:
    Mar 18, 2013
    Posts:
    6
    That works too! I'll use that instead :)

    I never found an answer to my first problem, no. As a workaround, I'm simply not parenting the objects in question and use a non-unity object to manage them collectively.

    Another question: The Scale9Sprite help page talks about setting margins on a texture. Can I use it on a sprite also? In other words, can I pack all my Scale9Sprites together in one atlas and use a frame index to access them? I'll try soon if I can answer my own question, but the documentation is vague ;)
     
  27. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    No .. the scale9sprite only takes an image, and does not work with sheets or atlasses (YET) .. It is on my todo list to support that.
     
  28. ekkiiiii

    ekkiiiii

    Joined:
    Apr 2, 2013
    Posts:
    3
    Hello! First of all, thank you for great Framework. When i was choosing between all the available options, it was pretty much "the one" for me feature-wise.
    Now I have created a tilemap in TILED and the auto-generation of the colliders worked great, but i have problems implementing the collision detection.
    I have a GameObject for my player that has an AnimatedSprite Component attached to it containing all the animations. My problem is that the AnimatedSprite (which i have set to "Trigger" physics, because i do not need any type of physics behaviour), does not seem to collide with the generated tilemap-colliders. I have delegated the onCollision method with debug-output, but when the character moves over the areas with the colliders nothing happens. When i set the tilemap itself to collidable i get collision detection, but only for the complete map, not for my collision-tiles.
    I assume this has something to do with the fact that according to the documentation "Collidable sprites only collide with other collidable sprites", but how can i get those auto-generated colliders to work then?
    Also i have some tiles set to "collide"" and some to "trigger" to be sure but none of those works for me.

    Edit: The approach mentioned in the reply below also doesn't work, the AnimatedSprite was already set to collidable.
     
    Last edited: Oct 11, 2013
  29. Vehrmt

    Vehrmt

    Joined:
    Sep 27, 2013
    Posts:
    2
    I recommend you set your AnimatedSprite to collidable as well - from my recent experience, things just work out smoother that way. You can sort it out so that no actual physics actions are performed while maintaining its use in raycasting or any other method you use for detection. (I can't remember exactly how at the moment, but it was relatively easy to set up)

    Now, for my part...
    Thanks for developing the framework and still supporting it so long after the release! I was worried I wouldn't be able to get help with some of my Orthello-related questions. I really like working with it, but as a beginner, I am often confused.

    One problem I'm having at the moment is related to tinting. Currently, I simulate fog-of-war in a grid-based TBS by tinting sprites. Visible sprites are tinted white, and sprites that have gone out of vision are tinted grey. (The rest are black)
    My problem is this: When I try tinting with, for example, OTSprite.colorTint = color.Red, this works and I get red tiles as expected.
    However, if I try tinting with a custom color, for example OTSprite.colorTint = new Color(1,1,1), the tile is tinted to full white. This happens regardless of the values I use in creating the new color. I considered that the tinting function only supports predefined Unity colors, I can set it to any value via the Inspector. What am I doing wrong here?

    This is part of a bigger effort to implement some general lighting. I noted that the materials OT uses by default have lighting disabled. I would've liked to have used Unity's light objects in combinations with normal/specular maps for nice effects, but I don't understand how to change the material without breaking the framework.

    I have some other ideas that would result in a more rudimentary appearance (such as tinting, using .PNGs set to additive lighting), but I'd really like to be able to code in some dynamic lights. If it is possible, how would I go about getting Orthello's sprite objects to be recognized by Unity lights? (Or, if there are better ways, what should I do in general to get good lighting effects?)
     
    Last edited: Oct 11, 2013
  30. PinkPanter

    PinkPanter

    Joined:
    Sep 26, 2013
    Posts:
    4
    World3D

    Hi, I am trying to do game, where the level is 3d mesh, and all other object is a 2d sprite. I set OT.world = World3d(or just create OT-3D). But I don't feel any changes, I still can't move sprite in editor in Z-axis. All change that I have is a perspective camera, it's correct? I can move sprite by z-axis when game is play and, I think, i can move sprite by script. Can I move sprite in editor on z-axis, and if answer is no, can I move it by script or it will cause errors?

    Sorry for my bad English...
     
  31. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    To get a good collision you need to be sure that

    1. Your sprite is setup correctly to collide (trigger or collision using a rigidBody)
    2. The CollisionDepth of your sprite is at the right zValue ( where the tilemap colliders are )
    you can check this in your editor
    3. Make sure that the colliders are of the same type (collider or trigger). This because a trigger will not collider with a rigidbody collider.
    If I am correct you could set your Tilemap Generated colliders to be triggers by setting the tile property collision to "trigger"

    onCollision is for rigidBody colliders
    onTriggerEnter is for trigger colliders.

    Hope this helps.
     
  32. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Tinting is done using vertex colors and the results is actually determined by the shader that is used to draw the sprites. Orthello uses some default alpha blending shader that will use the vertex color to adjust the render color ( less than 1,1,1 will reduce a color channel , so 1,1,1 is original color pixel ). The default shaders that are used in Orthello also do not support lighting.

    To use a different approach , tinting or another way of rendering (using lights for example) means you will have to use another shader to do the drawing. This is actually very easy.

    read the online manual about extending the material cache
    http://www.wyrmtale.com/orthello/using-OT#materials

    It comes down to .. creating a specific material ( that uses a shader ) and putting that into the Orthello material system.
     
    Last edited: Oct 14, 2013
  33. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696

    World3D was created to support creating 3D focused UI elements, for example linking sprites to 3D objects. It is not optimal and not tested to create full games witth it. Could be a bit buggy even....

    But you should be able to set X/Y position using sprite.posiution and zValue using sprite.depth or transform.position.z
     
    Last edited: Oct 14, 2013
  34. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Hi, I'm trying to get the coordinates of a OTSprite that I made. The X Y are setted in 0, but I need to know how can I obtain the real coordinates in the screen, because the sprite is centered in the center of the screen. I used ToWorld and FromWorld functions without success.
     
  35. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    use (orthello) sprite.worldPosition to set/get the sprites position in world coordinates.
    use (unity) Camera.main.WorldToScreenPoint(worldPosition) to convert a world position to a screen position.
     
  36. Vehrmt

    Vehrmt

    Joined:
    Sep 27, 2013
    Posts:
    2
    Many thanks! I'll be looking into that.
     
  37. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Hi, thanks for the answers. I have one more for you.

    If I have 2 overlapping sprites, is possible to enable register input "true" in both of them? And listen the events?

    The foreground sprite will only detect drag phase start and drag phase move, and the background sprite will have some buttons (is like a scroll over a sprite)
     
  38. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    I think so .. but find it difficult to image what you are describing. Please try to descrive a bit more what you are trying to accomplish.
     
  39. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Ok.

    I have an OTClippingAreaSprite that is 400x600px. In the onInput of this clip area I call a function that do something like that:

    Code (csharp):
    1.  
    2.         public void forcedUpdate()
    3.         {
    4.             foreach (Touch evt in Input.touches)
    5.             {
    6.                 if (evt.phase == TouchPhase.Began)
    7.                 {
    8.                     //Debug.Log("Touch BEGAN");
    9.                 }
    10.                 else if(evt.phase == TouchPhase.Moved)
    11.                 {
    12.  
    13.                 }
    14.                 else if(evt.phase == TouchPhase.Ended)
    15.                 {
    16.                     if(evt.deltaTime < 220)
    17.                     {  
    18.                         //Debug.Log("Propagating touches DeltaPosition: " + evt.deltaPosition + " DeltaTime: " + evt.deltaTime );
    19.                         propagateTouch();
    20.                     }
    21.                     else
    22.                     {
    23.                         //Debug.Log("Touch END");
    24.                     }  
    25.                 }
    26.             }
    27.         }
    28.  
    29.  
    And when I call the function propagate, I just invoke theOnInput function of every child that the clip have like others sprites or custom buttons. I need that the clip area sprite receive first the touch events, because is scrollable in some way, and after that (in the TOUCH PHASE END), I propagate the events to the childs (in case that the user doesn't want to scroll and want to touch a button).

    I'm having a problem with this, and is that I can't know in the on Input of every child, if the mouse position was in the RECT of the child. I.E. a button.

    Sorry for my english, I don't know how explain better the situation.
     
  40. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    I think that when you are writing a 'custom' Input system, the best approach would be to really write all input handling and not propagating stuff to the regular sprite Input handlers .. this way you are mixing systems and things can become too complicated. So I really have no solution to your problem ..
     
  41. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Ok, thanks. Doesn't you know how to detect if the position of a "OT.view.mouseWorldPosition" is within the area of a Sprite" ? Because, this is my real problem now.
     
  42. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    maybe check that position against sprite.worldRect (or sprite.rect)
     
  43. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Thanks !! it works !! :)
     
  44. altheonix

    altheonix

    Joined:
    Oct 20, 2012
    Posts:
    19
    Hi, is there a way to set the spacing between letters? (OTTextSprite)

    I want to set the gap smaller.
     
  45. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    At this time, that should be setup in the atlas .. no very efficient i reckon ..
    so putting those settings on my todo list (horizontal/vertical spacing)
     
  46. altheonix

    altheonix

    Joined:
    Oct 20, 2012
    Posts:
    19
    Ah I see, hope the feature will be done soon. :D
     
  47. fsellanes

    fsellanes

    Joined:
    Jun 6, 2013
    Posts:
    15
    Hi. After a lot of tests, I noticed that maybe the OTClippingAreaSprite has a bug. My problem is that If I have a OTClippingAreaSprite with layer=16, and I set the layer to 16 to others sprites.. that are within the area of the OTClippingAreaSprite, the sprites appear far than the position that they should are. This bug, occurs in the mobile device, however this doesn't happen in the editor.

    I notice that if you drag the OTClippingAreaSprite a bit, the sprites with layer=16, get solved.

    You can test this problem in your example of "ClipSprites", if you go to the start function, and instead of the currently start:

    Code (csharp):
    1.  
    2. void Start () {
    3.     moveHandler.Desactivate();
    4. SetClipFactor(0);
    5. }
    6.  
    you write:

    Code (csharp):
    1.  
    2. void Start () {
    3.     clipArea = true;
    4. HandleClipArea();
    5. }
    6.  
    You will see that all the sprites will appear so tiny (far), and when you drag a bit the "moveHandler" game object, this problem get solved.





    Maybe I am missing some important things, or you can give me a solution or something, maybe some function that renderize all the sprites.. im not experienced in this area.

    Thanks.

    EDIT:

    This IF, in the OTClippingAreaSprite seems to do the trick (If I set it as comment)

    Code (csharp):
    1.  
    2.             if (clipped)
    3.             {
    4.                 //if (!worldRect.Equals(lastRect))
    5.                 //{
    6.                     Rect clipRect = worldRect;
    7.                     clipRect.xMin += clipMargin;
    8.                     clipRect.yMin += clipMargin;
    9.                     clipRect.width -= clipMargin;
    10.                     clipRect.height -= clipMargin;                         
    11.                     OT.ClipMove(gameObject,clipRect);
    12.                     baseVector = _clipCamera.transform.position;
    13.                     lastRect = worldRect;
    14.                     clipCamera.transform.Translate(offset);
    15.                 //}
    16.             }
    17.  
    Of course, this seems not be the best way to achieve this.

    Thanks.
     
    Last edited: Oct 21, 2013
  48. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    When I look at your solution, it seems to me that the worldRect of the sprite equals the last recorded Rect (lastRect). Maybe, in your situation, it is not initialized yet. The solution should be found in the area where the worldRect is calculated.

    Maybe a sprite.ForceUpdate() will (re-)calculate the worldRect and force the clipCamera initialization instead of the 'if clipped' that will execute the code each update Cycle ( which means too much cpu there... )

    Let me know if that worked?
     
  49. dyego_s

    dyego_s

    Joined:
    Mar 26, 2013
    Posts:
    24
    Hi!

    I'm trying to use the multi resolution with Resources file. But it's not working as I expected.

    I have two Atlas, one for 1024x600 and another for 1920x1200, but when I try to change it, the images stay in the same size. ex: Default Atlas is 1920x1200, but when I call the 1024x600(OT.textureResourceFolder = "MDPI";), the images size stay in 1920x1200 (I also change Pixel Perfect Resolution to 1024x600). I looked in the Atlas Cocos2d prefab and I noticed, the Atlas size did not change.

    is it normal?

    I thought that when I change the file with "OT.textureResourceFolder", all images will be resized to its respective size. So I can change the resolution that adapts with the device resolution.
     
  50. mas

    mas

    Joined:
    Nov 14, 2010
    Posts:
    696
    Using the TextureResourceFolder, your sprites will not be resized, just the texture will be adjusted en replaced by one out of your ResourceFolder, that can have a bigger or lower resolution.

    You need to set OT.view.alwaysPixelPerfect = false, so your camera will auto-zoom to the correct screen dimensions and your sprites will have the same size on each device.

    Check the example that is in the /Orthello/Examples/0 - Simple examples/Multi Resolution to see how it works.