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

Pages: [1]
Releases / Re: 2D Toolkit 2.3.0
« on: November 13, 2013, 06:00:49 am »
How big is your sprite collection? 20-30 minutes sounds crazy long. I'd have expected Unity to crash way before that....  :o
It should be safe in Unity 4.2.x, but make a backup of your project before updating!

I have 1881 sprites on a single spritesheet 2048x2048 with 20% wastage, most of the sprites are diced by 16x16. And there are a few more images to add.
Even selecting the spritecollection prefab takes about a minute to show the "open editor" button at the inspector tab.
it takes 20-30 min to build (commit changes) to the sprite collection
Unity does crash if I dicrease the dice size even more, like 8x8.

When optimizing fillrate, is there any automatic way to do that in 2DToolkit like was shown in unity 4.3? (that alpha-cutout thing)
I do use the Custom Render Mesh in the sprite collection, but having an automatic way to do that would help a lot, and cut the time needed on production pipeline.

You can use sprite dicing to improve fillrate. helped me push fps from 12-ish to 60 even on 4thGen iPods.
check http://www.unikronsoftware.com/2dtoolkit/doc/2.00/advanced/sprite_optimizations/sprite_optimizations.html

Releases / Re: 2D Toolkit 2.3.0
« on: November 12, 2013, 11:12:15 pm »
Is safe to upgrade to tk2d v2.3.0 while still using Unity 4.2.x?

I use very large sprite collections to the point that adding one more sprite halts everything to a crawl and takes 20 - 30 min to rebuild.

Support / Re: Recommended method for simple particle effects?
« on: February 21, 2013, 05:10:34 am »
Hi Unikron,

We have been working for a few weeks now and we have a working prototype now, so we just did a few tests with real devices
on iphone and ipads everything is ok between 40 to 60 fps but with 4g ipods we sometimes have drops below 20 fps.
We are still using the built in physics collision detection for bullets

You mentioned earlier there could be another ways to test if a sprite (aka a bullet) hits another sprite (aka a character)
could you please elaborate on those, so we can see if we can get better performance on older devices


Support / Re: 3.5, and the drawcall inflation effect.
« on: January 15, 2013, 03:36:51 am »
Hi Unikron,

I am using the GameObject.Instantiate() method, passing a stored prefab instance as argument. similar to http://forum.unity3d.com/threads/76851-Simple-Reusable-Object-Pool-Help-limit-your-instantiations!

I will debug to check the reference value between the prefab and instantiated object materials.

On a previous post you mentioned that now draw calls are not a big concern on iOs development, do you have an estimate of how many drawcalls can be considered "ok"?


Support / Re: 3.5, and the drawcall inflation effect.
« on: January 13, 2013, 11:23:34 pm »

I am not sure if the effect I am experiencing has something to do with this but here it goes

I have a prefab consisting on an Empty Game Object that has one AnimatedSprite and one Sprite as child
The animated sprite is my character with the set of animations and the "static" sprite is just a circular shadow therefore there is a overlap of the two.

The character has its own spriteCollection while the shadow is on another spriteCollection

the funny thing:
If I drag the prefab into the editor as many times as I want the drawcalls will remain steady about 8
If I create instances of the prefab by an ObjectPool object/script as soon as a character appears on the screen it adds 2 drawcalls giving an ever increasing number of drawcalls as long as the spawner stay active
If I remove the shadow sprite from my prefab and retry both previous test the drawcalls remain steady about 8

as far as this goes I can get to the conclusion to ask to my graphic artist to include the shadow with the character animations but I really want to understand why is this happening so I can design my prefabs in a more drawcall safe manner.


Support / Re: Recommended method for simple particle effects?
« on: December 19, 2012, 03:19:41 am »

I implemented the proposed solution to my bullet system, it works great! thanks

I also applied some of the gathered knlowdege to build a basic Particle Engine script component. hope this code can help someone.

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

public enum EmitterType{

public class ParticleEngine : MonoBehaviour {

public class tk2dParticle{
private ParticleEffect effect;
public tk2dSprite Shape;
public float LifeTime;
public float StartTime;
public Vector3 StartPosition;
public Vector3 Velocity;
public Vector3 Acceleration;
public float Speed;
public Vector3 SpinFactor;
public Vector3 Scale;
public float StartScaleFactor;
public float FinalScaleFactor;
public float StartAlpha;
public float FinalAlpha;
public Color Tint;
public Color FinalTint;

public tk2dParticle(ParticleEffect effect, tk2dSprite shape){
this.effect = effect;
this.Shape = shape;

public void Update(float totalElapsedTime){
float localElapsedTime = (totalElapsedTime - this.StartTime);
float normalizedTime = localElapsedTime / this.LifeTime;
float clippedNormalizedTime = Mathf.Clamp01(normalizedTime);

if(localElapsedTime > this.LifeTime){

Vector3 position = this.StartPosition + this.Velocity * this.Speed * localElapsedTime + 0.5f * this.Acceleration * localElapsedTime * localElapsedTime;
this.Shape.transform.position = position;
this.Shape.transform.Rotate(this.SpinFactor * Time.deltaTime);
this.Shape.scale = this.Scale * MathS.Lerp(this.StartScaleFactor, this.FinalScaleFactor, clippedNormalizedTime);
Color shapeColor = this.Shape.color;
shapeColor = MathS.ColorLerp(this.Tint, this.FinalTint, clippedNormalizedTime);
shapeColor.a = Mathf.Clamp(MathS.Lerp(this.StartAlpha, this.FinalAlpha, clippedNormalizedTime), 0f, 255f);
this.Shape.color = shapeColor;

public class ParticleEffect{
public bool isEnabled;
public float EmitStart;
public float EmitStop;
public float Rate = 3.0f;
public bool InheritMovement = false;
public EmitterType EmitterType;

public tk2dSprite Shape;
public float LifeSpan = 30.0f;
public float LifeSpanVariation = 20.0f;

public Vector3 Direction;
public Vector3 DirectionVariation;
public float Speed = 1.0f;
public float SpeedVariation = 0.0f;
public Vector3 Acceleration;
public Vector3 Spin;
public Vector3 SpinVariation;
public Vector3 Rotation;
public Vector3 RotationVariation;

public float Scale = 1.0f;
public float ScaleVariation = 0.0f;
public float FinalScale = 1.0f;
public float FinalScaleVariation;

public float Alpha = 255.0f;
public float AlphaVariation;
public float FinalAlpha = 255.0f;
public float FinalAlphaVariation;

public Color Tint = Color.white;
public Color FinalTint = Color.white;

private List<tk2dParticle> availableParticles;
private List<tk2dParticle> activeParticles;
private List<tk2dParticle> particlesToDeactivate;

private float timePerParticleEmision;
private float timeSinceLastEmision;
private ParticleEngine engine;

public ParticleEffect(){
this.EmitStart = 0;
this.EmitStop = 10;
this.Rate = 3.0f;

public void Initialize(ParticleEngine engine){
this.engine = engine;
float maxParticles = 0.0f;
if(this.EmitStop == -1)
maxParticles = (this.LifeSpan + LifeSpanVariation +1) * this.Rate;
maxParticles = (this.EmitStop - this.EmitStart) * this.Rate;

this.timeSinceLastEmision = 0.0f;
this.timePerParticleEmision = 1.0f / this.Rate;

this.availableParticles = new List<tk2dParticle>((int)maxParticles);
this.activeParticles = new List<tk2dParticle>((int)maxParticles);
this.particlesToDeactivate = new List<tk2dParticle>((int)maxParticles);

tk2dParticle tempParticle = null;
for(int i=0; i < maxParticles; i++){
tk2dSprite obj = (tk2dSprite)Instantiate(this.Shape);
tempParticle = new tk2dParticle(this, obj);

internal void EmitParticle(){
if(this.availableParticles.Count == 0)
tk2dParticle particle = this.availableParticles[0];

GameObject obj = particle.Shape.gameObject;
obj.transform.parent = null;
obj.transform.position = this.engine.selfTransform.position;

particle.LifeTime = Random.Range(this.LifeSpan - this.LifeSpanVariation, this.LifeSpan + this.LifeSpanVariation);
particle.StartTime = Time.time;
particle.StartPosition = obj.transform.position;
particle.Velocity = Quaternion.Euler(
Random.Range(this.DirectionVariation.x * -1, this.DirectionVariation.x),
Random.Range(this.DirectionVariation.y * -1, this.DirectionVariation.y),
Random.Range(this.DirectionVariation.z * -1, this.DirectionVariation.z)) * this.Direction;
particle.Speed = Random.Range(this.Speed - this.SpeedVariation, this.Speed + this.SpeedVariation);
particle.Acceleration = this.Acceleration;
Random.Range(this.Rotation.x - this.RotationVariation.x, this.Rotation.x + this.RotationVariation.x),
Random.Range(this.Rotation.y - this.RotationVariation.y, this.Rotation.y + this.RotationVariation.y),
Random.Range(this.Rotation.z - this.RotationVariation.z, this.Rotation.z + this.RotationVariation.z));
particle.SpinFactor = new Vector3(
Random.Range(this.Spin.x - this.SpinVariation.x, this.Spin.x + this.SpinVariation.x),
Random.Range(this.Spin.y - this.SpinVariation.y, this.Spin.y + this.SpinVariation.y),
Random.Range(this.Spin.z - this.SpinVariation.z, this.Spin.z + this.SpinVariation.z));

particle.Shape.scale = this.Shape.scale;
particle.Scale = particle.Shape.scale;
particle.StartScaleFactor = Random.Range(this.Scale - this.ScaleVariation, this.Scale + this.ScaleVariation);
particle.FinalScaleFactor = Random.Range(this.FinalScale - this.FinalScaleVariation, this.FinalScale + this.FinalScaleVariation);

particle.StartAlpha = Random.Range(this.Alpha - this.FinalAlphaVariation, this.Alpha + this.AlphaVariation);
particle.FinalAlpha = Random.Range(this.FinalAlpha - this.FinalAlphaVariation, this.FinalAlpha + this.FinalAlphaVariation);

particle.Tint = this.Tint;
particle.FinalTint = this.FinalTint;

internal void killParticle(tk2dParticle particle){

private void deactivateParticle(tk2dParticle particle){
GameObject obj = particle.Shape.gameObject;
obj.transform.parent = this.engine.selfTransform;

internal void Update (float elapsedTime) {
bool isEmitting = false;
if(this.EmitStop == -1)
isEmitting = elapsedTime >= this.EmitStart;
isEmitting = elapsedTime >= this.EmitStart && elapsedTime <= EmitStop;
this.timeSinceLastEmision += Time.deltaTime;
if(this.timeSinceLastEmision >= this.timePerParticleEmision){
float numOfEmisions = this.timeSinceLastEmision / this.timePerParticleEmision;
numOfEmisions = Mathf.CeilToInt(numOfEmisions);
for(int i=0; i< numOfEmisions; i++)
this.timeSinceLastEmision = 0.0f;
foreach(tk2dParticle particle in this.activeParticles)
if(this.particlesToDeactivate.Count >0){
foreach(tk2dParticle particle in this.particlesToDeactivate)

public bool AutoStartEngine = true;
public ParticleEffect[] Effects;

internal Transform selfTransform;
internal bool isRunning;
private float startTime;

public void StartEngine(){
this.startTime = Time.time;
this.isRunning = true;

public void StopEngine(){
this.isRunning = false;

// Use this for initialization
void Start () {
this.selfTransform = this.gameObject.transform;
if(Effects == null)
for(int i=0 ; i< this.Effects.Length; i++)

void Awake(){

// Update is called once per frame
void Update () {
if(Effects == null)
float elapsedTime = (Time.time - this.startTime);
for(int i=0 ; i< this.Effects.Length; i++)

Any improvement or sugestion would be appreciated

Support / Re: Recommended method for simple particle effects?
« on: December 14, 2012, 05:26:34 pm »
Thanks, let me implement those functions on my code instead of the physics. I'll post here my results

Support / Re: Recommended method for simple particle effects?
« on: December 13, 2012, 04:43:04 pm »
Hi unikron,

I already have a Bullet9mm prefab which consists of a tk2dSprite with a Bullet script attached, the script has properties as damage, range, firedById, etc.
I also have a ObjectPoolComponent gameObject with an ObjectPool script attached where I am pre-instantiating 200 Bullet9mm.
On the update method of the bullet script I test if the distance between startPosition and the currentPosition is greater than range, then the object is returned to the pool.
On my Weapon script I get a Bullet gameObject from the pool and apply a force to it +  a random slight change on the startPosition and force direction to generate a spread of bullets instead of a single line.
On my CharacterController script I test for any Trigger Enter event and apply the damage if necesary and return the bullet to the pool.

Could you explain how to build the deterministic path?, especially for parabolic ones (as I plan to have grenades) and I guess I didnt get the chain of projectiles thing, does that mean the spread of bullets? or bullets + trail?
should I still use the trigger event to test for collisions? or should I use some sort of function of the collider to test if it contains a specific point/vector

Support / Re: Recommended method for simple particle effects?
« on: December 13, 2012, 05:36:04 am »
This sounds like the thing I need!!!
more detail would be appreciated

Support / Re: Recommended method for simple particle effects?
« on: December 13, 2012, 01:30:53 am »
Yes we are targetting for mobile devices.

The bullets doesnt move at a high-ish speed as we want to give the player a small chance to dodge them
On our previous project we used up to 25 characters at a time, we might want to stretch that number up a little further. the final number will be set after playtesting the prototype based on dificulty.

Could you elaborate on the custom system idea?, as I have no clue where to start if not using GameObjects with tk2dSprite scripts attached.

Support / Re: Recommended method for simple particle effects?
« on: December 12, 2012, 05:01:46 pm »
Well, I plan to have up to 200 bullets for a given time. will depend on the number of on-screen enemies
and trails for a few bullets like rockets, lasers and such.
also plan to have dynamic explosions, fire +  smoke +  debri with a growing sphere collider for the splash damage.

[side note]
what would you suggest to propell bullets, use iTween or add a rigid body component and apply some force?
[end of side note]

Support / Re: Recommended method for simple particle effects?
« on: December 11, 2012, 11:16:21 pm »
Any thoughts how to implement something like the particle system to build things like 2D bullets & 2D explosions?
with collision events and all that stuff

Support / Re: Automatic generation of animated sprite
« on: December 06, 2012, 09:19:53 pm »

Could you elaborate on the offline method? I am looking to automate the process of creating animation objects and their clips from a specified sprite collection. As after the graphic artist gets done with all the drawing and stuff I would have to deal with setting about 2870+ frames to their corresponding animation clips.

I have a solid background on C#, but I am new to this unity stuff

Support / Re: Fog and Spot Light
« on: December 06, 2012, 06:52:08 pm »
Have someone used the "2D Volumetric Lighting system" available on the asset store? http://reverieinteractive.com/2dvls

I am thinking to give it a try

Support / Re: A Way to Combine Sprite Collections?
« on: December 06, 2012, 06:34:43 pm »
Some thing like this would come in handy, for example on my current project I have 52 sprites for each character (probably will increase as we create more content) and we have 10 diferent characters.

for level design would its more easy and tidy to have one spriteCollection per character
but performance wise would be better to have one or two 4096x4096 sprite collections with all the characters sprites on them the downside would be to deal with 520+ dropdown when setting frame animations.

another solution (at least for me) would be to have the option to use instead the dropdown a popup a window and be able to filter items by name.

any thoughts on that? thanks in advance

Pages: [1]