Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - ricke

Pages: [1]
1
Support / Mixing Unity 2D Animation with 2D Toolkit
« on: September 03, 2016, 02:58:45 am »
Is it possible to mix Unity 2D animation with 2D Toolkit?  It seems like I'd basically be transitioning all my sprites away from tk2dSprites to Unity 2D sprites in order to use Unity 2D bone animation, and with that the main underpinnings of 2D Toolkit (sprite collections, multi-resolution support, etc).  Is that an accurate statement or am I missing something?  Any thoughts would be appreciated.  Thanks.

2
Support / Difficulty with Multi-Resolution and CurrentPlatform
« on: August 13, 2016, 10:24:31 pm »
So I'm working on a space shooter game with 2D Toolkit 2.5.6 and I'm trying to setup multi-resolution sprite collections as the docs below explain.  I initially tried to setup in my game, but due to my issues, I created a test project to hammer it out.  Unfortunately, I've gotten the same results in both projects.  :(

http://www.2dtoolkit.com/doc/2.5/advanced/platform_specific_sprite_collections.html

I want my game to run natively at 1920 x 1080, so I set my Current Platform to 4x and then added 1x and 2x platforms in the sprite collection settings.  My sprite sizes are 64 x 64 (4x), 32 x 32 (2x), and 16 x 16 (1x).  It appears to be generating the proper 1x, 2x, and 4x atlases in the Project directory, so that looks good.  However, I always seem to be getting the 1x version of the sprites, no matter which resolution I select on the Game screen.  I've looked around on the forums and it seems like I'm doing the right thing, but I've got to be missing something. :) 

In the example project, I'm spinning up a GameController object that sets the CurrentPlatform in the Awake method, then I create an instance of a prefab of my Ship, Enemy, and Shot in the Start method.  Here's the code for my GameController:

Code: [Select]
using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour
{
    public GameObject playerPrefab;
    public GameObject enemyPrefab;
    public GameObject shotPrefab;

    private GameObject _player;
    private GameObject _enemy;
    private GameObject _shot;

    void Awake()
    {
        if (Screen.height >= 900)
        {
            tk2dSystem.CurrentPlatform = "4x";
        }
        else if (Screen.height >= 480)
        {
            tk2dSystem.CurrentPlatform = "2x";
        }
        else
            tk2dSystem.CurrentPlatform = "1x";
    }

    void Start()
    {
        // Create new instances of sprites
        _player = Instantiate<GameObject>(playerPrefab);
        _enemy = Instantiate<GameObject>(enemyPrefab);
        _shot = Instantiate<GameObject>(shotPrefab);

        Debug.Log("Current Platform: " + tk2dSystem.CurrentPlatform);
        Debug.Log("Screen Resolution: " + Screen.width + " x " + Screen.height);
    }

}

Here's a screenshot with my enemy texture at 1x, 2x, and 4x respectively above my ship, enemy, and shot sprite prefabs to show the difference.  No matter what Preview resolution I use in the Game window, the sprites are always the 1x size.



I can send my example project along if that would be helpful.  Any thoughts would be appreciated.  Thanks.

3
Support / Kinematic Physics, Breakout, and the death of my sanity
« on: June 07, 2016, 06:55:59 pm »
Hi there.  I'm still new to Unity and 2D Toolkit and have been spending a lot of my time the past few weeks trying to learn all that I can.  Partly as a learning exercise and partly because I thought it would be fun, I'm trying to roll over an old version of a breakout clone that I made several years ago.  As ball mechanics are key in such a game, I have been focusing my beginning efforts on getting those nailed down tight.  And despite my best efforts, Unity has been laughing at my pitiful attempts to make it work and feasting on my soul in the process. :o  So I thought I'd see if anyone here has some ideas on what I could be doing wrong.  I'm not sure if this is a problem with 2D Toolkit, Unity, or me... but I thought I'd start here.  :)

Just some background to begin on my project structure (I didn't list all components on my game objects, only the ones I thought pertinent to the issue):
  • Using a Orthographic tk2dCamera object for viewing my game with a Preview / Native Resolution set at 1920 x 1080 and 1 Pixel Per Meter.
  • Four boundary objects that surround my play area (top, bottom, left, right) with Box Collider 2D component set on each of them.
  • Obligatory paddle object with Rigidbody 2D, Box Collider 2D, and PlayerController components.  It is set as Kinematic on the Rigidbody.
  • PointBrick Prefab with tk2dSprite and Box Collider 2D components.  Sprite is 64 x 45, Upper Left anchor, and Box Trimmed collider in sprite collection.
  • Ball Prefab with tk2dSprite, Rigidbody 2D, Circle Collider 2D, and BallController components.  Sprite is 16 x 16, Middle Center anchor, and User Defined collider in sprite collection.  It is set as Kinematic and Trigger on the Rigidbody.
  • GameController object with GameController script that sets up random lines of bricks and manages ball lives / spawning.
  • PlayerController script handles paddle movement in FixedUpdate method by modifying paddle transform from mouse movement.
  • BallController script handles checking for collisions with boundaries and bricks.  Currently, I don't destroy any bricks on collision as I'm testing, so they stick around for further collisions.
  • I have two layers at play in my project - Default and Ball.  My paddle and bricks live on the Default layer and any balls live on the Ball layer.  I did this to avoid collisions between balls on the screen.

With that said, my problem lies in my collision checking in the BallController script.  Observation of the game play at this point shows the collisions working, but inconsistently (and strangely so).  My goal has been to do a simple reflection of the ball, whether on a boundary or a brick... in other words, I reverse the x / y axis of the ball appropriately based on what collided with the ball.  The boundaries are straightforward in this regard, but the bricks are giving me fits. 

I'm trying to use a RaycastHit2D to determine my collision point and reflect the ball properly, but for the life of me I can't get it operate consistently.  The ball will perform several collisions flawlessly, even tightly packed collisions between bricks.  Then boom... the ball just decides to continue right through a brick like nothing happened.  My debugging seems to indicate the collision occurs but it doesn't change direction.  Next time... it reflects off the same brick just fine, but will pass through a different brick later on.  Rinse and repeat.

Here's my BallController code for reference.  Perhaps another set of eyes will catch something I'm missing or perhaps something I'm doing wrong.  Any help would be greatly appreciated.

Code: [Select]
using UnityEngine;
using System.Collections;

public class BallController : MonoBehaviour
{
    private GameController _gameController;
    private Rigidbody2D _rb;
    private CircleCollider2D _collider;
    private tk2dCamera _camera;
    private bool _keepAlive;

    // Use this for initialization
    void Start()
    {
        // HACK: Keep the balls on the board for now
        _keepAlive = true;

        // Get a reference to the game controller script
        _gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();

        // Get a reference to the rigid body for the ball
        _rb = GetComponent<Rigidbody2D>();

        _collider = GetComponent<CircleCollider2D>();

        //Get a reference to the camera
        _camera = FindObjectOfType<tk2dCamera>();

        Debug.Log(string.Format("Spinning up new ball -- Position: {0},{1}  Velocity: {2},{3}", transform.position.x, transform.position.y, _rb.velocity.x, _rb.velocity.y));
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        Debug.Log(string.Format("Before Collision: {0},{1}", _rb.velocity.x, _rb.velocity.y));

        if (other.gameObject.CompareTag("PointBrick"))
        {
            RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y), _rb.velocity, 50.0f, LayerMask.GetMask("Default"));
            if (hit.collider != null)
            {
                Debug.Log(string.Format("Hit -- Brick Transform: {0},{1}  Ball Transform: {2},{3}  Collision Point: {4},{5}", hit.transform.position.x, hit.transform.position.y, transform.position.x, transform.position.y, hit.point.x, hit.point.y));
                Debug.Log(string.Format("Brick Bounds -- Min: {0},{1}  Max: {2},{3}  Center: {4},{5}",
                    hit.collider.bounds.min.x, hit.collider.bounds.min.y, hit.collider.bounds.max.x,
                    hit.collider.bounds.max.y, hit.collider.bounds.center.x, hit.collider.bounds.center.y));

                if (hit.point.x <= hit.collider.bounds.min.x || hit.point.x >= hit.collider.bounds.max.x)
                    _rb.velocity = new Vector2(-_rb.velocity.x, _rb.velocity.y);
                else if (hit.point.y <= hit.collider.bounds.min.y || hit.point.y >= hit.collider.bounds.max.y)
                    _rb.velocity = new Vector2(_rb.velocity.x, -_rb.velocity.y);
            }
        }
        else if (other.gameObject.CompareTag("BoundaryLeft") || other.gameObject.CompareTag("BoundaryRight"))
            _rb.velocity = new Vector2(-_rb.velocity.x, _rb.velocity.y);

        else if (other.gameObject.CompareTag("BoundaryTop"))
            _rb.velocity = new Vector2(_rb.velocity.x, -_rb.velocity.y);

        else if (other.gameObject.CompareTag("BoundaryBottom") && _keepAlive)
            _rb.velocity = new Vector2(_rb.velocity.x, -_rb.velocity.y);

        else if (other.gameObject.CompareTag("Player"))
            _rb.velocity = new Vector2(_rb.velocity.x, -_rb.velocity.y);

        Debug.Log(string.Format("After Collision: {0},{1}", _rb.velocity.x, _rb.velocity.y));
    }
}

4
Support / Designing graphics for multiple resolutions
« on: May 28, 2016, 01:19:34 am »
Hi there. I'm new to 2D toolkit, and this is more of a general question from a graphic design standpoint.  When you're creating your game, how do you draw your graphics at an appropriate size so that they scale to different resolutions nicely? For example, suppose I'm going to target 16:10 and 16:9 aspect ratio screens.  Obviously, that covers several different screen resolutions. Would you generally develop several different sprite collections at different sizes to meet each of those resolutions? Or would you develop one set of sprites (at the largest resolution size) and let 2D toolkit scale things appropriately?

I'm just trying to get a feel for the number of assets I need to create and at what resolution I should create them at. In general, it's better to downscale large images to small images than to upscale small images to large images as that's where the blurry comes in, correct?

Any thoughts would be appreciated. Btw, just bought this today and having spent the last week getting my hands around Unity's 2D, this package has some really great features that make life much easier. Thanks for the awesome work, I'm looking forward to bending it to my will. :D

Pages: [1]