2D Toolkit Forum

2D Toolkit => Support => Topic started by: mammothboy on February 21, 2013, 05:10:30 pm

Title: Lerp colors/alpha and javascript
Post by: mammothboy on February 21, 2013, 05:10:30 pm
Hello.
I can't seem to be able to change through lerp the alpha of the sprites, how can i do it?
Also, i only understand javascript and the scripts os 2dtoolkit come in C#, i already did the "Setup for Javascript" thing, but nothing changed, all scripts are still C#.

Thank you for your time.
Title: Re: Lerp colors/alpha and javascript
Post by: unikronsoftware on February 21, 2013, 11:46:21 pm
Setup for JavaScript lets you access the scripts from JavaScript, it won't change the code for you. C# and JS are surprisingly similar to each other. You should be able to convert the no problem with a tiny bit of understanding.

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

public class TutorialSpriteScript : MonoBehaviour {

tk2dSprite sprite;

// Use this for initialization
void Start () {
    sprite = GetComponent<tk2dSprite>();
}

// Update is called once per frame
void Update () {
        if (Input.GetKeyDown(KeyCode.A))
        {
            sprite.color = Color.red;
        }
        if (Input.GetKeyDown(KeyCode.S))
        {
            sprite.color = Color.white;
        }
    }
}

becomes...

Code: [Select]
#pragma strict


var sprite : tk2dSprite;

function Start() {
sprite = GetComponent(tk2dSprite);
}

function Update() {
if (Input.GetKeyDown(KeyCode.A))
{
sprite.color = Color.red;
}
if (Input.GetKeyDown(KeyCode.S))
{
sprite.color = Color.white;
}
}