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

Pages: [1]
1
Thanks for the reply.

I'm not sure I understand this though: "bounds will be the same / close enough as long as your source images are the same size", as what I have here doesn't agree with that statement. The two source images aren't the same size.

I'm using the 2x and 4x platforms, with 2x as the default.
  grid-block-small@2x is 80x80 pixels
  grid-block-small@4x is 160x160 pixels

Irrespective of which platform is loaded in the inst property, I get a bounds of 80x80 for sprite 'grid-block-small'. That is the desired behavior for what I'm doing, but is that correct?

2
The code I pasted above had a number of issues. It seems that the bounds don't change per platform size (and using halfTargetHeight was just totally wrong), so it can be simplified to this:

Code: [Select]
      tk2dSpriteCollectionData spriteCollectionDataInst = this.spriteGroup.SpriteCollectionData.inst;
      tk2dSpriteDefinition definition = spriteCollectionDataInst.GetSpriteDefinition(this.name);
      Bounds bounds = definition.GetBounds();
      size = new IntVector2(
         Mathf.RoundToInt(bounds.size.x),
         Mathf.RoundToInt(bounds.size.y)
      );

So essentially the only difference is using the .inst property.

3
Hi,

I want to retrieve the 'native/standard' size of a sprite prior to instantiating one. This would be fairly simple to do except that I'm also using multiple platforms on the sprite collection. Running spriteCollectionData.GetSpriteDefinition() results in an exception because the spriteDefinition array has no elements. (Is that correct, or a bug?) Instead, one has to go spriteCollectionData.inst.GetSpriteDefinition(), which works, but will return a different definition based on which platform is currently active. (I.e. At 2x I'd get say, 40x40, and at 4x I'd get 80x80)

In terms of setting positions and sizes of sprites, I'm working at 1024x768, which corresponds with the '2x' sprite collection. So, when I want to retrieve a sprite's width, I always want the 2x measurement, effectively allowing me to ignore the 4x platform's existence.

I've written the following code which works around this issue, but am concerned about it being unsupported:

Code: [Select]
      tk2dSpriteCollectionData spriteCollectionDataInst = this.spriteGroup.SpriteCollectionData.inst;
      tk2dSpriteDefinition definition = spriteCollectionDataInst.GetSpriteDefinition(this.name);
      Bounds bounds = definition.GetBounds();
      size = new IntVector2(
         Mathf.RoundToInt(bounds.size.x * spriteCollectionDataInst.halfTargetHeight),
         Mathf.RoundToInt(bounds.size.y * spriteCollectionDataInst.halfTargetHeight)
      );

As you can see, I access the .inst and retrieve the definition for the current platform, then multiply the bounds by the current platform's halfTargetHeight to get the 'native' size.

Is there a better way to achieve this, or is the above an acceptable way of doing it?

Pages: [1]