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 - Ben

Pages: [1]
1
Support / Mobile device resolutions
« on: May 11, 2013, 11:28:15 am »
Hi,

How 2D Toolkit solves the problem of different resolutions on mobile devices? tk2dCamera has two different settings for resolution, that is, native resolution and camera resolution. Say, I set both of them to 800x1280, which is the resolution of Nexus 7, and now if I run my game on an Android device with a smaller resolution eg. 540x960 the game doesn't scale down to fit the screen and large part of the stage is outside the screen.
Other mobile game frameworks, for instance AndEngine, have dedicated functions that scale proportionally the stage up and down depending on the device resolution. So if the game is built for 800x1280 it'll fit proportionally to 540x960 or 480x800. How that problem is solved in 2D Toolkit?

2
Support / Collider and tk2dSprite
« on: May 07, 2013, 08:37:09 am »
Hi,
Is there any method to retrieve an instance of the class tk2dSprite using a Collider?
By default a collider can return a game object but not a sprite. I'm using the below code to drag sprites, which works nicely, however the object returned by the function hit.collider.gameObject is of type GameObject, not tk2dSprite. If I change the object obj to be of the type tk2dSprite and cast the object returned by hit.collider.gameObject to tk2dSprite the code returns an error. Is there any other method to reference the sprite detected by a collider?

GameObject obj;
if (Input.GetMouseButtonDown(0)) {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;           
            if (Physics.Raycast(ray,out hit))
            {               
                obj = hit.collider.gameObject;
          }
}

3
Support / Sprite collision detection
« on: May 05, 2013, 07:38:43 pm »
Hi,
I am using raycasting to detect which object has been clicked, however the code I've used detects only manually created game objects such as cubes or spheres. I have a group of sprites created dynamically from prefabs and those remain undetected while clicking on them. It looks like there is no collision detection occurring on those sprites. I've use the following code:

if (Input.GetMouseButtonDown(0)) {
          Ray ray = cam.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;         
          if (Physics.Raycast(ray,out hit,1000))
          {
            Debug.Log(hit.collider.tag);            
          }
      }

I'm certainly missing something here. I'd appreciate any suggestions.


4
Support / Object reference not set to an instance of an object
« on: May 03, 2013, 10:46:12 am »
Hi,

I'm getting the error 'Object reference not set to an instance of an object'. I've attached the following script to an empty game object, it is supposed to create a subclass of a sprite. Any help is very much appreciated.


public class Box : tk2dSprite {
   
    private tk2dSprite sprite;
   
    void Awake () {
       
        base.Awake();
       
        GameObject go = new GameObject();
        tk2dSprite sprite = go.AddComponent<tk2dSprite>();
        sprite.color = Color.red;
        sprite.scale = new Vector3(300, 300, 1);       
        sprite.Build();
    }
   
    // Use this for initialization   
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
   
    }
}


Pages: [1]