i am trying to make a sprite hole effect like @1:37 in this video
the code (Objective-C for cocos2d) is here
after searching around for a way to do this and not finding one
http://answers.unity3d.com/questions/784388/dynamically-hide-a-section-of-a-sprite-using-anoth.html
i made my own by scaling 4 solid sprites around one center sprite
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class GateMask : MonoBehaviour
{
public Image Center;
public Image East;
public Image North;
public Image South;
public Image West;
private float _scale;
private const float _scaleDown = .0001f;
private const float _scaleUp = 22f;
private float _alpha;
private const float _alphaDown = 1f;
private const float _alphaUp = 0f;
private const float _time = .75f;
private const float _timeDelay = .333f;
private Action _downAction = null;
public float Scale
{
get { return _scale; }
}
private void Start()
{
SetActive(false);
Down(DoTest);
}
private void DoTest()
{
StartCoroutine(Test());
}
private IEnumerator Test()
{
yield return new WaitForSeconds(3f);
Up();
}
private void SetUp()
{
HandleAlpha(_alphaUp);
HandleScale(_scaleUp);
}
public void Down(Action action)
{
_downAction = action;
SetActive(true);
SetUp();
Ease.Go(this, _alpha, _alphaDown, _time, HandleAlpha, null, EaseType.ExpoOut);
Ease.Go(this, _scale, _scaleDown, _time, HandleScale, SetDown, EaseType.ExpoOut);
}
private void SetDown()
{
HandleAlpha(_alphaDown);
HandleScale(_scaleDown);
if (_downAction != null)
{
_downAction();
_downAction = null;
}
}
public void Up()
{
SetDown();
Ease.Go(this, _alpha, _alphaUp, _time, HandleAlpha, null, EaseType.ExpoIn);
Ease.Go(this, _scale, _scaleUp, _time, HandleScale, Disable, EaseType.ExpoIn);
}
public void HandleAlpha(float value)
{
_alpha = value;
var color = Center.color.SetAlpha(_alpha);
Center.color = color;
East.color = color;
North.color = color;
South.color = color;
West.color = color;
}
public void HandleScale(float value)
{
_scale = value;
Center.transform.localScale = new Vector3(_scale, _scale, 1f);
var deltaScale = 1f - _scale;
if (deltaScale < -1)
deltaScale = -1;
if (deltaScale >= -1f)
{
var delta = new Vector3(deltaScale, deltaScale, 1f);
var test = Vector3.one + delta;
var v = new Vector3(test.x, 1f, 1f);
var h = new Vector3(_scale, test.y, 1f);
East.transform.localScale = v;
North.transform.localScale = h;
South.transform.localScale = h;
West.transform.localScale = v;
}
}
private void Disable()
{
SetActive(false);
}
private void SetActive(bool active)
{
Center.gameObject.SetActive(active);
North.gameObject.SetActive(active);
East.gameObject.SetActive(active);
South.gameObject.SetActive(active);
West.gameObject.SetActive(active);
}
}
it works well for this one case (scale a full screen hole)
but i also want to be able to move the hole in other cases like the spotlight in the video
and i suspect there is an easier way to do all this?
reverse mask?
cutout?
shader?
idk?
any help would be appreciated.
please & thanks