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.


Messages - JerryCic

Pages: [1]
1
Support / Re: How do i build a box collider at runtime.
« on: February 14, 2012, 06:27:36 am »
I figured this one out myself.

I was overthinking it. Setting the boxCollider.bounds.extents will not do it.
You have to use these:

tk2dSprite.boxCollider.size
tk2dSprite.boxCollider.center

on the parent sprite.

Jerry

2
Support / How do i build a box collider at runtime.
« on: February 14, 2012, 02:33:41 am »
Hi

I have a sprite in the hierarchy, it has a box collider placed there using the toolkits' edit.
At runtime, i add several other sprites of various sizes to the right of the initial sprite as children.

I can use the bounds extents of all the sprites to create a vector3 that is the extent of the box collider that i want to build.

I can also determine where the center of that collider should be.

I have tried to modify the existing collider, by setting its bounds.extents vector. this did not work.

basically I want a collider that covers the entire set of sprites.

How can i modify the collider or simply create a new collider that essentially will cover the entire set of sprites?

I have a script attached to the parent sprite. the problem is that the script doesnt execute for the children. The script allows the entire group to move its position via mouse or touch drag and drop with glide and boundaries.

If I create a box collider for each sprite, then i would have to place the script in each sprite. That would mess up some of my persistant variables in that live from update to update within each script intance.

I have tried having an empty game object act as the container, as well as trying the polygon convex mesh. I have tried the build() function. I am plugging away but have come up against the wall.

Thanks
Jerry C

3
Support / Re: Still can't place a sprite in the right place.
« on: February 14, 2012, 02:02:08 am »
Yes!

That did it! I can now achieve perfection.

Thank you for your time.

JerryC

4
Support / Re: Still can't place a sprite in the right place.
« on: February 13, 2012, 01:09:14 am »
Hi

when i execute this line:

Bounds bounds=myBackgroundSprite.GetUntrimmedBounds();

I get an error. Array index out of range
The line of code is the return line in the Bounds definition

   public Bounds GetUntrimmedBounds()
   {
      var sprite = collection.spriteDefinitions[_spriteId];
      return new Bounds(new Vector3(sprite.untrimmedBoundsData[0].x * _scale.x, sprite.untrimmedBoundsData[0].y * _scale.y, sprite.untrimmedBoundsData[0].z * _scale.z),
                        new Vector3(sprite.untrimmedBoundsData[1].x * _scale.x, sprite.untrimmedBoundsData[1].y * _scale.y, sprite.untrimmedBoundsData[1].z * _scale.z));
   }

Jerry

5
Support / Re: Still can't place a sprite in the right place.
« on: February 12, 2012, 10:14:35 pm »
Hi

i have 1.56final

your example instantiates a sprite
my sprite is already instantiated.

I can find it as a game object
GameObject myBackground =  GameObject.Find("spBackground");

how do i find it as a tk2dSprite?
What is the equivalent of this?
tk2dSprite myBackground=tk2dSprite.Find("spBackground");

so that i may expose the functions in question.

EDIT this is your code:
************************************************
   // position first sprite at 100, 245, and 10 units away from the camera
       sprite.transform.position = cam.ScreenToWorldPoint(new Vector3(100, 245, 10));
      
       GameObject newSprite = GameObject.Instantiate(sprite.gameObject) as GameObject;
      
       // get untrimmed bounds of this object
       Bounds bounds = sprite.GetUntrimmedBounds();
      
       // you can do this if the objects have the same dimensions
       newSprite.transform.position += new Vector3(bounds.extents.x * 2.0f, 0, 0);
      
       // but really what you need is
       //Vector3 secondBounds = newSprite.sprite.GetUntrimmedBounds();
       //newSprite.transform.position += new Vector3(bounds.extents.x + secondBounds.extents.x, 0, 0);
*****************************************

"newSprite" is clearly a GameObject. The lines after the (//but really) imply
that GetUntrimmedBounds() returns a Vector3 but I get an error
Also what is "newSprite.sprite" refferring to? sprite is not a property of GameObject.


Thanks
 Jerry

6
Support / Re: Still can't place a sprite in the right place.
« on: February 12, 2012, 08:30:28 pm »
Hi and thanks

I'm sure the answer is in there somewhere but!!!!

GetUntrimmedBounds() does not seem to exist as a function in my version on Unity.

Any ideas?

Also i cannot find any documentation in the unity reference manual


7
Support / Re: Still can't place a sprite in the right place.
« on: February 12, 2012, 04:54:46 pm »
Thanks for responding

Both sprites have anchor settings as dead center.



8
Support / Still can't place a sprite in the right place.
« on: February 12, 2012, 05:57:37 am »
Hi

Sorry to be so confused at such a simple task.

I have a 800x480 sprite placed at 0,0,10
I have a 120x400 sprite i want to place so that the lower left corner matches the lower left corner of the larger sprite.
my camera is ortho size=1
my target height is 480

I have tried to use the ScreenToWorld and visa versa but cannot get it to line up.
Everything has pixel perfect set up.

I have tried this:
           
            // find the center of the screen and large (background) sprite
            Vector3 v = myCamera.WorldToScreenPoint(new Vector3(0,0,0));
            // move 340 pixels to the left of center
            // move 40 pixels down from center
            Vector3 s = new Vector3(v.x - 340, v.y - 40, v.z);
            GameObject.Find("Staff").transform.position = s;

but it places it too far to the left like about 40 pixels too far.
The y coordinate looks ok.
What am i doing wrong?

Thanks
Jerry           

9
Thank you for your response

I still cant figure out how to retrieve the width of my sprite.
The scale is 1,1,1 and is the same no matter what the size of the sprite.
my "spGClef" scale is 1,1,1
my "spMeasure" scale is 1,1,1
but the two sprites are 120 pixels wide and 560 pixels wide respectivly
Is there a way that i can determine the width of the sprite in pixels at runtime?
Inside the program, i can only see/set the scale and position.

Thanks
Jerry

10
Support / how to determine the exact position when instantiating a prefab.
« on: February 12, 2012, 01:19:49 am »
Hi
 
I have a gameobject called "Staff".
It is the parent of one prefab called "spGClef".
When i click on a button, i want to make the staff into one that has 6 children. 1 "spGClef", 4 "spMeasure", and 1 "spEnd".
I can do all that quite well.
What i cannot seem to do is get the positions as perfect end to end arrangement.
My sprite collections have "Target Height"=480.
My camera scale is 1,1,1 ortho size=1.
From Trial and error i have discovered that one pixel=.004166666 in the scale of x or y
Since the width of my "spGclef" is known to be 120, then my first measure must be placed 120 pixels to the right of the "spGClef" object. That is (.004166666 * 120)=0.5.

1) how can i determine the exact width of my sprite relative to the screen.width in pixels?
2) how can i determine mathematically the magic number (.00416666 in my case) so that i can get exact end to end placement of sprites dynamically at runtime?

EDIT: I also need to add a box colider to the resulting collective object so i need to know the final size for the collider.

Thank you up front.
Jerry C

11
Support / Versions and How to upgrade.
« on: February 11, 2012, 05:57:36 pm »
Please pardon my lack of knowledge.

I have Unity 5.4.1
I have 2dToolkit 1.51a

I have downloaded the 1.56 Final

Before i do anything, Do i have to upgrade my current version of Unity? (to 5.4.2)?

If so, thats ok, Its just that i tend to not upgrade unless i have to.
This odd behavior comes from Microsoft upgrades that break things.

The other question is where do i place my ".unitypackage"?
I dont even know where my 1.51a is.
I found a folder "C:\Program Files\Unity\Editor\Standard Packages" but my 2dtoolkit package is not there.
But everything is working fine.

I want to upgrade to 2dTK 1.56 because i need diceing.

Thank You
Jerry C

Pages: [1]