Author Topic: Panel clipping of objects with atlases made in tk2d possible?  (Read 8166 times)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Is this possible? Right now it's not working and I don't understand the code behind the clipping methods, so it's hard to understand why making a child GO in an NGUI hierarchy with a tk2dSprite on it does not clip.

You may ask why I want to do this... I have a complex tk2d atlas structure for the actual in game 2d game I'm making and duplicating the entire atlas contents for mobile would make the game way too big. 

Any suggestions?

Thanks.

Edit: I also just noticed none of the objects under the Panel that use tk2d atlas sprites are affected by the UIPanel alpha settings either...
Edit2: I've tried faking this by placing a widget at the top and bottom of my screens with Z closer to the camera than that of the tk2d's Z but since it's on another panel as soon as i set the Z of an object closer to the camera in one panel it completely draws the whole panel contents over the top of everything in the contents of the panel I need to display.
« Last Edit: July 19, 2013, 04:20:38 PM by Majicpanda »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Panel clipping of objects with atlases made in tk2d possible?
« Reply #1 on: July 19, 2013, 06:55:57 PM »
tk2d and NGUI are two completely different packages, and you are trying to get one of them to affect the other -- something that's not going to happen. NGUI does clipping by swapping its shaders from "Unlit/Transparent Colored" to "Unlit/Transparent Colored (SoftClip)" under the hood. You can try setting your tk2d sprite to use that shader, but as I said -- two different packages are not meant to integrate with one another.

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Panel clipping of objects with atlases made in tk2d possible?
« Reply #2 on: July 20, 2013, 12:01:12 AM »
I wasn't assuming it would work out of the box immediately, but I was hoping the clipping simply worked with any Unity object with the right shader.  Unfortunately it looks like adding that shader to the tk2d atlas material makes the sprites not render at all and would be inefficient anyway since that would change every object in my game to that shader.

Is there any way to get around the other issue I have with trying to "mimic clipping" by simply putting a sprite over the top of the tk2d sprite on the Z?  If I have a Panel on Z = -10 with a background, label, and fake clip sprites on the top and bottom that I want to slide my other Panel that has dragpanel contents and draggable panel on it it gets completely hidden the minute I set just 1 of the sprites Z closer to the camera than the thing I'm trying to clip.

Panel (Z = -10)
- Background behind the drag panel contents
- Fake clip objects at top and bottom of camera view, z = -15

Panel (DraggablePanel) (Z = -11)
- GO (DragPanelContents) (UIGrid)
-- GO
-- GO

All the drag panel content items are supposed to slip under the fake clip sprites, but setting them to -15 draws the entire top Panel over the top of the 2nd panel.
-- ETC...
« Last Edit: July 20, 2013, 12:17:36 AM by Majicpanda »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Panel clipping of objects with atlases made in tk2d possible?
« Reply #3 on: July 20, 2013, 04:00:48 AM »
You have to write a custom shader for your tk2d objects that would support clipping the same way NGUI does.

...or not use the tk2d sprites, and instead use NGUI ones. Not sure why you are doing that to begin with.

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Panel clipping of objects with atlases made in tk2d possible?
« Reply #4 on: July 20, 2013, 02:17:08 PM »
Well... tk2d has a really easy animation system to work with that has frame based event management so that I can trigger some frame perfect effects.

Aside from that all the equipped items are in world space and some animated like weapons and custom anchor points that tk2d has nice support for, so the problem is that if I wanted it in NGUI it would be harder to do what i'm doing and if I duplicated all the images over that would make the game a lot larger and it's for mobile.

I'm hoping I'm approaching it all wrong I mean that would be great, but I don't see a way to use the same sprites I need in tk2d also over in ngui atlases without doubling my texture memory and downloaded game size.

simon.yu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Panel clipping of objects with atlases made in tk2d possible?
« Reply #5 on: July 01, 2014, 11:21:55 AM »
every time if you have problem work with NGUI you can try this:http://gototokyo.blog.163.com/blog/static/283834201461112928688/