Author Topic: Offset animation  (Read 6555 times)

glaubergft

  • Guest
Offset animation
« on: April 12, 2012, 09:08:53 AM »
Hi,

Here's an example what I'm trying to achieve with NGUI: http://migre.me/8E6pQ

I would like to animate a TiledSprite background like this gif. Is there any way to increment it's material's offset to simulate this animation? I tried to  attached an script to a TiledSprite to manipulate the material.

The closest I got was messing up the atlas inherited from UIWidget:

function Update()
{
   transform.GetComponent("UITiledSprite").material.mainTextureOffset.x+=Time.deltaTime*0.1;
}

Is it possible to perform this with NGUI?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offset animation
« Reply #1 on: April 12, 2012, 02:26:41 PM »
Adjusting the material offset will have adverse effects as it will affect everything using that atlas, and it's not what you want. Tiling is generally only possible with textures that have the right side matching the left, and bottom side matching the top. Since sprites within the atlas take up only a part of the texture, you can't simply say "tile it". This is why I had to create the UITiledSprite class to begin with. What it actually does is creates geometry behind the scenes, multiplying your sprite over and over until it fills the designated area. Currently there is no way to adjust its tiling, but if you're code-savvy, you could add this functionality by modifying UITiledSprite.

db82

  • Guest
Re: Offset animation
« Reply #2 on: November 02, 2012, 06:48:22 AM »
Hi Just wondering if there is a way to accomplish this now? Would be great be able to offset the texture of a tiled sprite so we can do scrolling backgrounds with just 1 widget.

Thanks for any response to this

PhilipC

  • Guest
Re: Offset animation
« Reply #3 on: November 02, 2012, 08:34:43 AM »
My thought on this would be that you should use a UITexture and make it "tile" how you would expect using the material properties. You could then make this animate.

keysosaurus

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Offset animation
« Reply #4 on: October 03, 2013, 11:51:00 AM »
Did you get this working?

Trying to adjust the material properties on a UITexture to make the the texture animate, but it doesn't change at runtime.

Cheers

swogdog

  • Guest
Re: Offset animation
« Reply #5 on: November 05, 2013, 11:56:30 AM »
I also would like to know if anyone got this working.  I'm trying to animate the X and Y under "UV Rectangle" on a UITexture.  It looks like it works in the preview window, but doesn't animate at runtime.

I'm still on version 2.6.4

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offset animation
« Reply #6 on: November 05, 2013, 12:07:24 PM »
I'm still on version 2.6.4
http://www.tasharen.com/forum/index.php?topic=6328.0

After you update, alter UIWidget.drawCall.dynamicMaterial.

swogdog

  • Guest
Re: Offset animation
« Reply #7 on: November 05, 2013, 01:35:44 PM »
Yes, but you have warned in the upgrade notes that you made some large changes that will break things in the latest version.  I have this project due to my client in 2 weeks and will not do an upgrade to 3.x so close to completion.  Does anyone know of a workaround or something?

swogdog

  • Guest
Re: Offset animation
« Reply #8 on: November 05, 2013, 01:37:42 PM »
Just noticed there is a 2.7.  Will that be enough of an upgrade to fix this issue?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Offset animation
« Reply #9 on: November 06, 2013, 08:29:59 AM »
If you can't update, I suggest animating the original material's UV offset, not the UITexture. This way the UI won't be rebuilt.