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

Pages: 1 [2] 3
16
Support / Re: tk2dSprites render pink when changing scene / using LoadScene
« on: February 05, 2016, 05:54:18 pm »
Holy sh*t, I found it (actually a colleague pointed me in the right direction)! The problem lies within Unity 5.3. Apparently, every call to the material properties of a tk2dSprite within the first frame of the Start() breaks about everything. If I skip the first frame in the Start(), everything work perfectly!

So if I do this hack, it works!
Code: [Select]
// this works
private IEnumerator Start(){
     yield return new WaitForSeconds(0);
     Material m = settingsBackgroundButton.GetComponent<Renderer> ().materials [0];
     Debug.Log(m[0].name);
}

// this generates pink sprites
private void Start(){
     Material m = settingsBackgroundButton.GetComponent<Renderer> ().materials [0];
     Debug.Log(m[0].name);
}

A second thing to keep track of is that these issues DON'T affect any -builds- that were made with 5.3. So the sprites in my build for iOS are all there (and not pink), even though the same build turns everything pink in the editor / playmode.

I did some other tests on the default Unity prefabs (sprites, cubes, etc), but it doesn't seem to affect those. I guess that this bug has something to do with Unity 5.3 in combination with tk2d? Something has changed in 5.3 that affects the allocation of the materials within the tk2d framework (in 5.2.4 everything works without hassle).

So yeah, I'm rambling. If anyone needs more info, let me know. For now I revert back to 5.2.4 (I don't feel like changing all my Start voids into IEnumerators). Hopefully unikron can come up with a fix, that would be awesome (or we can wait for the next update of Unity 5.3 and see what happens then).

17
Support / Re: tk2dSprites render pink when changing scene / using LoadScene
« on: February 05, 2016, 05:03:08 pm »
I've created a clean test-environment (one sprite, two scenes, two scripts, just the bare basics) to rule out any other scripts or frameworks (pooling, tweening, etc), and it is still happening. I have the ZIP folder with the env, if you would like to have a look. Let me know where to send this (it's 2.1 mb).

18
Support / tk2dSprites render pink when changing scene / using LoadScene
« on: February 04, 2016, 06:21:11 pm »
Okay so here's a problem that I currently have with _all_ my projects (I'm guessing since the 5.3 update): every time I change a scene (using SceneManager.LoadScene("sceneName"); ) al lot of my sprites render pink (in fact: only the sprites where I access the material property). This is due to a missing Material in the Mesh Renderer (somehow the Mesh Renderer looses it's material). The strange thing is that when I start the loaded scene on it's own, everything works perfect. Let me explain step by step:

- If I run my "Game" scene, everything is peachy
In my Scene-view everything renders a-ok (see screenshot: GAMESceneViewNotRunning)
In my Game-view everything renders a-ok, after starting the "Game"-scene (see screenshot: GAMESceneRunning)

Now I'm currently using an "Init" scene which addresses all the properties of the camera. I'm using this scene to decide what ratio, resolution and view (landscape / portrait) I am going to use. This "Init" scene is basically an empty scene with a single tk2dCamera, and the following script:

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

public class InitializeStageScript : MonoBehaviour
{
void Start ()
{
// Set targetframe
Application.targetFrameRate = 60;

// set tk2d platform based on width or height (what's biggest)
float sWidth = Screen.width;
float sHeight = Screen.height;
float highest = 0;
bool isPortrait = false;

if (sWidth > sHeight) {
highest = sWidth;
} else {
isPortrait = true;
highest = sHeight;
}
if (highest > 1136) {
tk2dSystem.CurrentPlatform = "4x";
} else if (highest > 480) {
tk2dSystem.CurrentPlatform = "2x";
} else {
tk2dSystem.CurrentPlatform = "1x";
}

// optimize tk2d platform for platform based on maxSpriteSize
// TODO ALWAYS: change for max texture size in game (see 4x atlas in collectiondata)
// if atlas0.png in 4x folder is 2048x2048 then maxTextureSize < 2048
if (tk2dSystem.CurrentPlatform == "4x" && SystemInfo.maxTextureSize < 2048) {
tk2dSystem.CurrentPlatform = "2x";
} else if (tk2dSystem.CurrentPlatform == "2x" && SystemInfo.maxTextureSize < 1024) {
tk2dSystem.CurrentPlatform = "1x";
}

// setup level based on ratio
string prefix;
string ratio;
if (isPortrait) {
prefix = "Running in PORTRAIT mode with an aspect of: ";
if (Camera.main.aspect >= 1f) {
ratio = "1:1";
} else if (Camera.main.aspect >= 0.795f) {
ratio = "4:5";
} else if (Camera.main.aspect >= 0.745f) {
ratio = "3:4";
} else if (Camera.main.aspect >= 0.655f) {
ratio = "2:3";
} else if (Camera.main.aspect >= 0.615f) {
ratio = "10:16";
} else if (Camera.main.aspect >= 0.595f) {
ratio = "3:5";
} else if (Camera.main.aspect >= 0.575f) {
ratio = "10:17";
} else if (Camera.main.aspect >= 0.555f) {
ratio = "9:16";
} else if (Camera.main.aspect >= 0.415f) {
ratio = "9:21";
} else {
ratio = "NOT FOUND SET TO 9:21";
}
} else {
prefix = " and running in LANDSCAPE mode with an aspect of: ";
if (Camera.main.aspect >= 2.325f) {
ratio = "21:9";
} else if (Camera.main.aspect >= 1.765f) {
ratio = "16:9";
} else if (Camera.main.aspect >= 1.695f) {
ratio = "17:10";
} else if (Camera.main.aspect >= 1.655f) {
ratio = "5:3";
} else if (Camera.main.aspect >= 1.595f) {
ratio = "16:10";
} else if (Camera.main.aspect >= 1.495f) {
ratio = "3:2";
} else if (Camera.main.aspect >= 1.325f) {
ratio = "4:3";
} else if (Camera.main.aspect >= 1.245f) {
ratio = "5:4";
} else if (Camera.main.aspect >= 1f) {
ratio = "1:1";
} else {
ratio = "NOT FOUND SET TO 1:1";
}
}
Debug.Log ("Game Initialized at: " + tk2dSystem.CurrentPlatform + "  " + prefix + ratio);
SceneManager.LoadScene ("Game");
}
}

So basically the script runs on Start and decides what to do with the tk2dSystem.CurrentPlatform (and other aspecs such as ratio). In this project I only use the tk2dSystem.CurrentPlatform setup, in others I also use the ratio (to setup my scene differently for different ratios). When it's finished, it runs the next scene (which is the "Game" scene mentioned earlier).

Anyway. When running the "Init" scene, everything turns into a hot pink mess:
- The "Init" scene runs, and sets everything up. This can be seen by the Log-statement in the console (see screenshot: INITSceneRunningStep1)
- The "InitializeStageScript" runs and loads the "Game" scene, but now everything is Pinky-pink. Also the material of the sprite is missing (see screenshot: INITSceneRunningStep2)

As said, the missing material (pink sprite) only happens to the sprite that I access through the material properties (i.e.:

Code: [Select]
Material[] m = GetComponent<Renderer>().materials;
I don't get any errors, or other strange behaviour. I found this thread: http://2dtoolkit.com/forum/index.php/topic,5247.msg24038.html#msg24038 but I'm not quite sure if it applies here (I also have no idea how to fix my problem based on that thread).

Can you help? This really sucks (as it applies to all my projects :( )

19
Support / Re: Extra transparent border in atlas?
« on: November 23, 2015, 09:53:46 am »
That makes much more sense. I'll switch between the two, see which works best.

I've used an exaggerated example btw (to see if it would work). My real PNG only has 2px of useless alpha space on top and bottom (the PNG is 128x128, so I think it will be fine. But adding only 1px of alpha space and set the trimming to false might be better.

Anyway, thanks!

20
Support / Re: Extra transparent border in atlas?
« on: November 20, 2015, 08:59:06 am »
Thank you for your response. I've decided to use a more pragmatic solution by editing my sprite.

As tk2d crops the added alphaspace from the PNG for the spritesheet (so a 128x128 square with a 64 padding on all sides (PNG is 256x256) still remains 128x128 in tk2d), I've added a small border of 1 px on the edge of the 256x256. This border has a opacity of 1% (so it's not visible in game, but there is still data so tk2d won't crop it off). This makes sure that the PNG stays 256x256 within the tk2d environment.

The aliasing on the original 128x128 square (within the 256x256) is now gone. I can rotate it as i please.

It's still a hack, but a more clean one I guess. I don't have to edit any code :)

21
Support / Re: Extra transparent border in atlas?
« on: November 19, 2015, 05:14:44 pm »
Sorry for kicking this old topic, but is there a solution within the tk2d anno 2015 for this? I've tried adding alphaspace in my PNG, but I still get jagged edges unfortunately.

I'm using a simple white square of 128x128 with 64px of padding on all sides (so the PNG is now 256x256), but it's still as jagged as the original 128x128 when rotating.

22
Support / Re: Tk2dCamera Picture in Picture effect?
« on: October 05, 2015, 11:42:34 am »
You can use the normalized viewport to clip output region.
Ah! Keeping the native and preview resolution in the same aspect (or the same) is the trick. I was trying to fix the square shape of the camera by tweaking these variables!

Thanks!

23
Support / Tk2dCamera Picture in Picture effect?
« on: October 05, 2015, 11:06:44 am »
I was wondering if it would be possible to create a so called picture-in-picture effect with the tk2dCamera?
I want to run a 'default' camera over my scene and I want to have a smaller TV-like square that follows a specific target within the scene.

It seems that I'm missing something? This can't be that hard right?

This effect:


I'm already using two tk2dCamera's in my scene (one for the HUD and one for the scene) because I need to zoom in and out with the scene camera, without the HUD being affected, which works like a charm. But I can't seem to set the third camera to a single square (it renders the whole sceen by default).

24
Support / Re: tk2dUIItem .OnHoverOut activated during click
« on: August 07, 2015, 10:07:08 am »
That's understandable, you have quite a few users at this point!

In case anyone needs this in the future, I think I got it changed correctly in the tk2dUIManager script under the "checkForHovers" section. I changed this...

Code: [Select]
if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
{
   hitUIItem = RaycastForUIItem( Input.mousePosition );
}
   else if (Input.GetMouseButton(0)) //if mouse button is down clear it
{
   hitUIItem = null;
}

...to this...

Code: [Select]
if (!isPrimaryTouchFound && !isSecondaryTouchFound && hitUIItem == null && !Input.GetMouseButton(0)) //if raycast for a button has not yet been done
{
   hitUIItem = RaycastForUIItem( Input.mousePosition );
}

If this isn't right please feel free to correct me. Everything seems to be working though :)
A big thank you for finding this fix!

25
Hi, Resources.Load would be way better, otherwise you'd be using up a lot of memory.
Awesome! Thanks!

26
Okay so this works!

I've  added a script on the tk2dSpriteFromTexture with the following code:

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

public class SpriteFromTexturePlatformScript : MonoBehaviour {

    public Texture[] test;
    private Texture xSprite;
    private int size = 0;

    void Awake(){

        if(tk2dSystem.CurrentPlatform == "4x"){
            xSprite = test[2];
            size = 4;
        } else if(tk2dSystem.CurrentPlatform == "2x"){
            xSprite = test[1];
            size = 2;
        } else {
            xSprite = test[0];
            size = 1;
        }
        GetComponent<tk2dSpriteFromTexture>().texture = xSprite;
       
        GetComponent<tk2dSpriteFromTexture>().spriteCollectionSize.type = tk2dSpriteCollectionSize.Type.PixelsPerMeter;
        GetComponent<tk2dSpriteFromTexture>().spriteCollectionSize.pixelsPerMeter = size;
        GetComponent<tk2dSpriteFromTexture>().ForceBuild();
    }
}

This adds the proper sprite (i.e. 1x, 2x or 4x) to the tk2dSpriteFromTexture and scales the pixelsPerMeter to either 1, 2 or 4.

In terms of loading and memory this is probably not the best way (adding all three sprites (1x, 2x and 4x) to the public Array. Would Resources.Load() be better in this situation?

Anyway, thank you for your quick responses once again!

27
Allright thanks! I'll try this.

You think this is the best way to tackle this problem? Would a second SpriteCollection be better (draw-call wise)?

28
So I manually (based on the tk2dSystem.CurrentPlatform value) add the correct PNG to the Sprite from Texture script, or am I reading this wrong?

29
Hi!

I've managed to create a spriteCollection that supports tk2dSystem.Currentplatform 1x, 2x and 4x. This all works great and very intuitive (thank you for that!). However I've found a small issue with my current setup:

Since I've added ALL my PNG's to the spriteCollection (including multiple background images (of 2560x1600 in the 4x category)) my spriteSize is significant (the 4x spriteSize is 4096x8192), which causes an all black game on my iPad Retina (the game runs perfectly on my iPad2 though cause the 2x spriteSize is smaller, oh the irony).

I've removed the background images from the spriteCollection and now everything runs perfectly (aside from the game not having backgrounds of course).

My question is: how can I use these backgrounds (with the 1x 2x and 4x platform-support in mind) without them adding up to the spriteCollection. Can I use SpriteFromTexture for this? And if so: how? (I've already tested this using my current setup, but it just takes the 1x version).

Keep up the good work and thank you in advance!

30
Support / Re: Sprites disappear and act weird when they are rotated
« on: June 08, 2015, 08:07:28 am »
Cool thanks!

Pages: 1 [2] 3