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 - wiley.a

Pages: [1]
1
Support / Re: Screen Rotation Problem
« on: November 02, 2012, 05:50:52 pm »
I think the black boarders are now my problem with some pillarboxing/letterboxing I am doing. Completely forgot about that. Thanks for your help

2
Support / Re: Screen Rotation Problem
« on: November 02, 2012, 05:37:39 pm »
I tried that and while the height is now right, the width appears wrong. I've swapped the values so they should be right but I must be missing something. I now get the image below but without the sections labelled "Other stuff".


3
Support / Re: Screen Rotation Problem
« on: November 02, 2012, 01:06:39 pm »
The resolution stuff will be correct on the device.

The problem is it isn't. Its fine in the editor though.

4
Support / Re: Screen Rotation Problem
« on: November 02, 2012, 12:46:44 pm »
On the main setup which is horizontal I am getting 796.5x530.6667 which when upscaled comes to 960x640 whcih is right. When I switch it to vertical using the supplied code I get 354.2224x531 which doesn't seem right to me despsite looking right in the editor (but not on the iOS device).

I have one override setup which is:

Name: Wildercard Override
Width: -1
Height: -1
Auto Scale: Fit Visible
Fit Mode: Center

5
Support / Re: Screen Rotation Problem
« on: November 02, 2012, 12:29:57 pm »
I am after changing the resolution with the device orientation, like the image below.



However, with the supplied code I am actually getting this:


6
Releases / Re: 2D Toolkit 1.80 + patch 1
« on: November 02, 2012, 11:57:22 am »
A while ago I was on the forums asking about moving sprites and their references between collections and eventually I got it working with 1.76. However now that I have updated to this version I have had to alter my script to account for the depreciation of tk2dSpriteCollection.textureRefs. I have updated it to use tk2dSpriteCollection.textureParams but its not working correctly. What should I be using in place of tk2dSpriteCollection.textureRefs?

Thanks

7
Support / Screen Rotation Problem
« on: November 01, 2012, 03:10:49 pm »
Hello

In the game I am working on we have both horizontal and vertical based levels. I want to be able to switch the camera's setup so that it displays horizontally on iOS when on a horizontal level but set it in portrait mode when on a vertical level. I am sure its simple to do this but I am obviously missing something. The horizontal setup works fine but that could be because most of the game is in horizontal. When the vertical code runs everything is rendered vertically (so portrait on the device) but it has massive pillar boxing going on. I'd post a screenshot but I can't, sorry. Hope I have explained it well enough.

Code: [Select]
public static void SwitchCameraTo(Orientation orientation)
{
// If the orientation is already correct, return early
if (orientation == GameController.CameraOrientation)
return;

GameController.CameraOrientation = orientation;

if (orientation == Orientation.Horizontal)
{
GameController.Camera.nativeResolutionWidth = 960;
GameController.Camera.nativeResolutionHeight = 640;

GameController.Camera.forceResolution = new Vector2(960, 640);

Screen.orientation = ScreenOrientation.LandscapeLeft;
}
else
{
GameController.Camera.nativeResolutionWidth = 640;
GameController.Camera.nativeResolutionHeight = 960;

GameController.Camera.forceResolution = new Vector2(640, 960);

Screen.orientation = ScreenOrientation.Portrait;
}
}

8
Support / Re: Automatically transfer a sprite between atlases?
« on: October 11, 2012, 02:49:06 pm »
Is there a way to test if a sprite or number of sprites will fit into a atlas before doing anything to either the source or destination atlases?

9
Support / Re: Automatically transfer a sprite between atlases?
« on: October 11, 2012, 12:37:15 pm »
As far as I can tell placing
Code: [Select]
EditorUtility.SetDirty(sprite); straight after the call to SwitchCollectionAndSprite() seems to have worked!  ;D

10
Support / Re: Automatically transfer a sprite between atlases?
« on: October 11, 2012, 12:33:11 pm »
I think it would be a very nice feature to have and I'm sure you can do a much better job than I am.

11
Support / Re: Automatically transfer a sprite between atlases?
« on: October 11, 2012, 12:18:56 pm »
In a way yes the scene isn't correctly updated which is where the problem is. Once the code I have posted has finished running the gameobjects that were using the old sprite correctly have their sprite component's collection name and sprite names set to use the one in the new atlas. However, upon attempting to move the same sprite to yet another atlas or even just closing and reopening the level, they aren't as they were changed anymore.

I shall try and other thing you suggested in a moment. And yes I am sure it is correctly finding what it needs and callign SwitchCollectionAndSprite() on them.

Currently we have 40+ atlases which have got pretty unorganised. Sprites appear in multiple atlases as they different themes in our game when they should be in some global atlas and generally we have a lot of wasted sprite as they haven't been organised really. I am trying to provide a nice, clean and easy way for us to be able to sort the atlases out without having to rebuild any of the levels because of lost collection/sprite references.

12
Support / Re: Automatically transfer a sprite between atlases?
« on: October 11, 2012, 11:57:04 am »
I am looking for a more permanent way of doing this and have nearly got it, just got one last (quite major) problem. So at the moment I have it so that you select two atlases (one source, one dest) and also the source sprite in the source atlas you wish to transfer. When I run it, it will correctly transfer the sprite between atlases and regenerates them (the atlas textures are correctly updated) and all occurences of the source sprite in the open scene are updated to use the new sprite in the dest atlas. However, when I try to move the moved sprite onto another atlas or even just close and reopen the scene the changed gameobjects return to the original atlas but just selects the first sprite in that atlas. Any ideas on this as I am sure I'm nearly there and its just frustrating me :(

Code: [Select]
public void Transfer()
    {
// Load the two collections
tk2dSpriteCollection sourceCol = AssetDatabase.LoadAssetAtPath(
"Assets/Main/Sprites/" + m_atlasNames[m_sourceAtlasIndex],
typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;

tk2dSpriteCollection destCol = AssetDatabase.LoadAssetAtPath(
"Assets/Main/Sprites/" + m_atlasNames[m_destAtlasIndex],
typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;

// ===============================

// Make a copy of the dest texture refs with a extra slot for the new one
Texture2D[] temp = new Texture2D[destCol.textureRefs.Length + 1];

for (int i = 0; i < destCol.textureRefs.Length; ++i)
temp[i] = destCol.textureRefs[i];

// The new sprite we are adding to the dest col
temp[temp.Length - 1] = sourceCol.textureRefs[m_sourceSpriteIndex];

// Set the copy
destCol.textureRefs = temp;

// Ensure the dest col is updated
tk2dSpriteCollectionBuilder.ResetCurrentBuild();
tk2dSpriteCollectionBuilder.Rebuild(destCol);

// =============================

// Make a copy of the texture params of the sprite that we are moving
tk2dSpriteCollectionDefinition defToCopy = sourceCol.textureParams[m_sourceSpriteIndex];

// Find the moved sprite in the dest col and then copy across the source params
for (int i = 0; i < destCol.textureParams.Length; ++i)
{
if (destCol.textureParams[i] == null)
continue;

if (destCol.textureParams[i].name == defToCopy.name)
destCol.textureParams[i].CopyFrom(defToCopy);
}

// Update the dest col
tk2dSpriteCollectionBuilder.ResetCurrentBuild();
tk2dSpriteCollectionBuilder.Rebuild(destCol);

// Now we need to go through the level and update any uses of the source sprite
FixupReferences();

// =============================

// Now that the sprite has been moved we need to null the reference in the source col
for (int i = 0; i < sourceCol.textureRefs.Length; ++i)
if (i == m_sourceSpriteIndex)
sourceCol.textureRefs[i] = null;

// Update the source col
tk2dSpriteCollectionBuilder.ResetCurrentBuild();
tk2dSpriteCollectionBuilder.Rebuild(sourceCol);

// Refresh sprite list
m_sourceSpriteIndex = 0;
PopulateSourceSprites();
    }

public void FixupReferences()
{
// Get the collection name we want to replace (used to search with)
string collectionNameToFind = "";

string[] split = m_atlasNames[m_sourceAtlasIndex].Split(new char[] { '/' });
collectionNameToFind = split[split.Length - 1].Split(new char[] { '.' })[0];

// Load the dest col
tk2dSpriteCollection destCol = AssetDatabase.LoadAssetAtPath(
"Assets/Main/Sprites/" + m_atlasNames[m_destAtlasIndex],
typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;

// Load the scene to alter
if (EditorApplication.OpenScene("SCENE_NAME"))
{
// Read the contents of the hierarchy
object[] hierarchy = GameObject.FindSceneObjectsOfType(typeof(GameObject));

foreach (object o in hierarchy)
{
GameObject go = (GameObject)o;

// Try and get the sprite component
tk2dSprite sprite = go.GetComponent<tk2dSprite>();

// No sprite component so return
if (sprite == null)
continue;

// The sprites collection name isn't the one we want to alter so return
if (sprite.collection.spriteCollectionName != collectionNameToFind)
continue;

// If the sprite names match, switch the collection and the sprite
if (sprite.collection.spriteDefinitions[sprite.spriteId].name == m_sourceSpriteNames[m_sourceSpriteIndex])
sprite.SwitchCollectionAndSprite(destCol.spriteCollection, destCol.spriteCollection.spriteDefinitions.Length - 1);
}

// Save the scene
EditorApplication.SaveScene();
EditorApplication.SaveAssets();
}
else
{
Debug.LogError("Failed to find " + "World1Level1");
}
}

13
Support / Re: Automatically transfer a sprite between atlases?
« on: October 09, 2012, 05:15:18 pm »
I have it mostly working but "fairly straightfoward" wouldn't be how I describe it. Maybe I've missed something obvious. Anyway, the trouble I am having now is that when I am searching through all of the scene files to find sprites of the type that I have just moved (moved to the destination atlas without removing the source to avoid the collection and sprite names becoming invalid), I can correctly identify the ones I want to update but as I update the first one I come across, it causes other sprites in the scene to get changed. I've managed to track the problem down to it being that after I use SwitchCollectionAndSprite() the spriteIDs of the others in the scene (on the same collection) get reordered.

Is there a way to tell it to just add the new sprite with the ID of the sprite count in that collection? Or maybe you have written something to handle this already and I haven't spotted it?

Thanks

14
Support / Automatically transfer a sprite between atlases?
« on: October 08, 2012, 02:31:32 pm »
Hello

Is it possible to script the transfer of a sprite between atlases and then regenerate both?

Thanks

Pages: [1]