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

Pages: [1]
1
Support / spriteDefinitions has empty values in it?
« on: December 11, 2014, 09:18:58 pm »
The sprites on one of my sprite sheets randomly come out like this image rather than the actual sprite:


This doesn't happen every time. I'm trying to pull out a random sprite with the following code added to t2dSpriteCollectionData which returns "blank" values:

Code: [Select]
public string GetRandomSpriteName()
{
return spriteDefinitions[Random.Range(0, spriteDefinitions.Length)].name;
}

Any suggestions on why this would return a value most of the time but the odd time it is an empty string? In the collection, every sprite has a name and yet this sometimes returns an empty string.

2
How would won save tk2dSpriteCollectionData to disk so that it doesn't have to be recreated at a later date? I'm guessing it wouldn't be able to be serialized and saved. I couldn't find a decent explanation and I've been fishing around the tk2d files for the past several hours for clues.

This is the code I have, it creates a sprite collection from a png file but the file save does not work because it wont let me serialize tk2dSpriteCollectionData.

Code: [Select]
using UnityEngine;
using System.Collections;
using System.IO;
using PixelShootLibrary;
public class PixelShootCreateTileSpriteCollectiona : MonoBehaviour {


string imageLocation = @"C:\Users\Euthyphro\AppData\Roaming\PixelShoot\MapTextures\stone16x16px.png";
string spriteCollectionDataLocation = @"C:\Users\Euthyphro\AppData\Roaming\PixelShoot\MapTextures\SpriteCollection.dat";
public tk2dSpriteCollectionData spriteCollectionData;
public Texture2D texture;
tk2dBaseSprite spriteInstance = null;

void Start ()
       {
CreateSpriteCollection ();
}
void CreateSpriteCollection()
{
FileManager fm = new FileManager();
if(File.Exists(spriteCollectionDataLocation))
{
spriteCollectionData = (tk2dSpriteCollectionData)fm.OpenStream(spriteCollectionDataLocation);
}
else
{
if(File.Exists(imageLocation))
{
byte[] fileData = File.ReadAllBytes(imageLocation);
spriteCollectionData = Resources.Load ("Sprites/TileMapCollection", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
texture = new Texture2D(288,270);
texture.filterMode = FilterMode.Point;
texture.LoadImage(fileData);
spriteCollectionData.textureFilterMode = FilterMode.Point;
string[] names = new string[256];
Rect[] regions = new Rect[256];
Vector2[] anchors = new Vector2[256];
for(int  y = 0; y < 16; y++)
{
for(int x = 0; x < 16; x++)
{
int pos = x+(16*y);
names[x+(16*y)] = pos.ToString()+"tile";
int offsetX = x;
int offsetY = y;
if(y > 0)
{
offsetY = y*16+(2*y);
}
if(x > 0)
{
offsetX = x*16+(2*x);
}
regions[x+(16*y)] = new Rect(offsetX, offsetY, 16, 16) ;
anchors[x+(16*y)] = new Vector2(offsetX, offsetY);
spriteCollectionData = tk2dSpriteCollectionData.CreateFromTexture(texture,tk2dSpriteCollectionSize.ForTk2dCamera(), names, regions, anchors);
}
}

fm.WriteStream(spriteCollectionDataLocation, spriteCollectionData);
}
}
}


}

3
I have about 40 tile maps and multiple layers, rather than modifying each one by hand and wishing I was a robot, I'm trying to write a script to do that. The problem is that this is leaving the old layers under the render data game object and creating the layers rather oddly. Obviously I'm doing this wrong, what is the best practice to add/remove tile map layers through code to ensure everything is taken care of?

Here is my code for what I have:

Code: [Select]
if(GUILayout.Button("Create Tile Map Layers"))
{
List<tk2dTileMapData> tileMapDataList = new List<tk2dTileMapData>();
tileMaps = FindObjectsOfType(typeof(tk2dTileMap)) as tk2dTileMap[];
Debug.LogError("Size: "+tileMaps.Count().ToString());
foreach (tk2dTileMap tileMap in tileMaps)
{
tileMap.data.tileMapLayers.Clear();
tileMap.BeginEditMode();

for(int i = 0; i < 5; i++)
{
tk2dRuntime.TileMap.LayerInfo newLayer = new tk2dRuntime.TileMap.LayerInfo();
newLayer.name = "Layer "+i.ToString();
newLayer.generateCollider = false;
newLayer.useColor = true;
newLayer.z = i;
newLayer.unityLayer = 20 + i;
newLayer.sortingOrder = i;
newLayer.hash = 0x70d32b98;
if(i == 1)
{
newLayer.generateCollider = true;

}
if(i == 0)
{
tileMap.data.tileMapLayers[i] = newLayer;
}
else tileMap.data.tileMapLayers.Add(newLayer);

Debug.LogError(tileMap.name+" i:"+i.ToString());
}
tileMap.EndEditMode();
}
}



4
Support / Setting Tilemap opacity to 100% opaque
« on: June 27, 2014, 09:12:02 pm »
It seems that when I build my tilemap through code, the tiles opacity is not 100%. This is problematic with lighting because it makes the tiles look somewhat transparent. What is more, when using multiple tile layers it causes the layers beneath to show through the top layer.

I've tried turning cursor tile opacity to 1.0 but I do not think this is where the problem rests.

The shader I'm using is tk2d/LitBlendVertexColor. I've tried every other shader as well and this problem persists.

The actual image files are 100% opaque but for some reason with tk2d they are showing up as somewhat transparent whenever I use any lighting shaders.

Any suggestions? How can I set the opacity by code, if this is necessary?


Thanks.

5
Support / Drawing sprites and merging together
« on: June 17, 2014, 10:48:26 pm »
For my project I need to merge two transparent sprites onto one sprite by sampling data from one and merging certain pixels of that sprite onto another. Is there a way with tk2d to do this? Looking through the support docs I don't see any functionality that allows a dev to even sample what colour is at a pixel coordinate of a sprite image. Any suggestions? Coming from Systems.Drawing (which isn't supported in Unity, I'm kind of looking fo something along the lines of Bitmap.GetPixel(x,y) to sample and then redrawing the image from there.

Thanks.

6
Support / Rendering path not lighting correctly
« on: April 09, 2014, 03:32:29 pm »
The rendering path seems to be cutting out and only displaying within a small box as you can see in the image below. In the editor, the lighting looks good, but in the game-preview the rendering path only lights a small box.



I've tried tweaking the settings and adjusting, any suggestions?


Thanks.

7
Support / IndexOutOfRangeException FindChunkAndCoordinate
« on: January 15, 2014, 07:10:50 am »
I receive the following error randomly when trying to modify a tile programatically. It is difficult because I cannot replicate it with any one tile, each time it seems to happen to a different tile. When the error does occur, tk2d stops working altogether and the scene has to be stopped and restarted.

Code:
Code: [Select]
tileMap.GetTileAtPosition(whichBlockToCheck,  out x, out y);
tileMap.SetTile(x, y, 0, -1);
tileMap.Build();

Error:
Code: [Select]
IndexOutOfRangeException: Array index is out of range.
tk2dRuntime.TileMap.Layer.FindChunkAndCoordinate (Int32 x, Int32 y, System.Int32& offset) (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMapChunks.cs:372)
tk2dRuntime.TileMap.Layer.GetRawTileValue (Int32 x, Int32 y, System.Int32& value) (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMapChunks.cs:384)
tk2dRuntime.TileMap.Layer.GetTileFlags (Int32 x, Int32 y) (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMapChunks.cs:428)
tk2dRuntime.TileMap.Layer.SetTile (Int32 x, Int32 y, Int32 tile) (at Assets/TK2DROOT/tk2dTileMap/Code/tk2dTileMapChunks.cs:450)
PLTileGridManager+<MineBlock>c__IteratorA.MoveNext () (at Assets/Scripts/PLTileGridManager.cs:606)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)

8
I'm trying to create an infinite map with pooled layers and chunks using tk2d. So far I've been able to implement a few different procedural generation algorithms to generate the tile map, but now I'd like to make the map infinite with the following logic. Just need to know how to use it with tk2d specifically to programatically control the layers.

The best way I see fit to do this is I plan to pool a new layer with 4x4 chunk set and use them as the player approaches the end of the current layer it is on. For example, I have a map with 4 x 4 chunks in each layer. I was thinking of creating another layer and as the player approaches the border of layer 0, then the next layer with chunkset is used from a pool and placed beside the previous. If a player is walking right and nears the border a layer, the next layer is pulled from the pool, rendered with the tiledata generated from my procedural generation algorithm, and placed. The previous layer is then pooled. If the player walks back or approaches the border again, the layer/chunk set is pooled.

I realize this is not the correct use of a layer but it seems like a fairly simple and quick way to approach this.

I figure I'll only need a pool size of 4 layers, each with 4x4sets of chunks. If the player approaches the border of the bottom right, then you would need to account for the right, bottom right, and bottom edges of the chunk as the player could move in any of these directions, in which case you need to be ready to account for this seemlessly.

i.e. each cube below is a layer from 0 to 3. The little "." is a player moving towards the bottom right. As the player approaches the border of layer 0, layer 1,2,3 are pulled from a pool and rendered with tiledata to seamlessly border layer 0.

x--------xx--------x
|   0      ||     1    |
|         . ||           |
x--------xx--------x
|     2    ||    3     |
|           ||           |
x--------xx--------x

If the player is approaching the left, same thing as above just different position.

x--------xx--------x
|   2      ||     1    |
|           ||           |
x--------xx--------x
|     3    || .  0     |
|           ||           |
x--------xx--------x


So my question in all of this is what is the best way to reposition and control layers programatically with tk2d? Specifically which methods? I find the documentation for tk2d somewhat lacking when it comes to the tilemap methods and classes outside of basic tk2d tilemap functions:(.


Thanks.

9
I'm trying to use Input.mousePosition to get mouse click location, however, I can't seem to convert it to the actual position in-game to move an object.

What I'm trying to do is obtain the actual position in game when a mouse is clicked based on a tk2dtilemap and using tk2dcamera. Transform coordinates are based off of the tilemap. I don't want the pixel coordinates based on lower left side of the screen and top right side of the screen, I'm trying to obtain the actual transform position so I can move an object to the point clicked using i.e. Vector3.Lerp(startVector, mouseClickVector, TIme.deltaTime);

I'm not sure of the math or how it works to convert the Input.mousePosition to the actual transform position? Could someone share how they've done this?


Thanks.

10
Support / NullReferenceException when using tk2dTextMesh
« on: September 13, 2013, 05:54:47 am »
I have the following code which keeps giving nullreferenceexception. It is almost identical to the example given in the documentation. The TextMesh comes attached along with a script called "PlayerObject.cs" (script below) to a prefabricated GameObject. The GameObject is instantiated by Controller.cs (script below). Is there something special that needs to be done to get textmesh working if the gameobject you want a textmesh running on is instantiated from another script?

Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
PlayerObject.Update () (at Assets/Scripts/PlayerObject.cs

PlayerObject.cs script:
Code: [Select]
using UnityEngine;
using System.Collections;
using ClassLibrary;

public class PlayerObject : MonoBehaviour {

public int playerID;
public string objectName;
public tk2dSpriteAnimator spriteAnimator;
public tk2dSprite sprite;
tk2dTextMesh textMesh;

void Start () {
        textMesh = GetComponent<tk2dTextMesh>();
        }
void Update ()
{
                     if(textMesh != null)
                    {
textMesh.text = "TEST";
                     //textMesh.text = objectName;
                       textMesh.Commit();
                      }
}

}


The above gameobject is instantiated from a separate controller script, Controller.cs:
Code: [Select]
GameObject po;
po = (GameObject)Instantiate(Character,vector,Quaternion.identity);
PlayerObject poScript = (PlayerObject)po.gameObject.GetComponent(typeof(PlayerObject));
po.name = goList[i].name;
poScript.playerID = goList[i].pId;
poScript.objectName = goList[i].name;
playersConnectedGO.Add (po);

11
Support / How to change sprite animation at run time with c#?
« on: September 10, 2013, 06:00:58 am »
I'm trying to figure out how to change the sprite animation library of a game object so I can change the current playing animation clip to one from a different library. Can someone please share how to do this in C#?

For example, one Library called "AnimationSetOne" with a dozen clips, and another library called "AnimationSetTwo" with another dozen. How can I change the current library of a game object so I can then use the .Play(anim); method to change a sprite animation clip? I want to be able to do this during run time in c#, could only find a javascript example that didnt work.



Thanks!

Pages: [1]