Author Topic: Tiled-sliced sprite ?  (Read 5427 times)

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Tiled-sliced sprite ?
« on: December 09, 2013, 09:26:03 AM »
Hello !

I was considering implementing a tiled-sliced sprite (with constant borders and a center that is tiled), but then it will be annoying to keep my changes when updating ngui... Would it be possible to include such a feature in the release version?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #1 on: December 09, 2013, 02:45:19 PM »
Don't.

Create a widget (ALT+SHIFT+W).

Add children sprites to this widget.
  • First, the tiled background. Make it anchored to the widget (default unified anchor setting)
  • Next the 4 sides -- left, right, bottom, top. Tiled sprites if you want them to be tiled vertically/horizontally. Anchor each to their respective side (also default unified setting if you set it when they are already in place)
  • Last, add the corners as regular sprites. Same thing with anchors -- turning on anchors with the sprite in place will automatically make it anchored correctly.


No code necessary.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #2 on: December 09, 2013, 03:40:39 PM »
I made this, since I was screwing around with the code anyhow.
"Advanced sprite" is a mix of tiled and sliced. You can choose to tile or slice the edges and the center independently or disable the center like on a regular sliced sprite.

This was made on 3.0.6 f7, so I'm not sure if it breaks everything when using 3.0.7+, so user beware. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #3 on: December 09, 2013, 04:10:45 PM »

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #4 on: December 10, 2013, 03:40:22 AM »
ArenMook : Thank you for your answer, however the point of my request was to avoid such a complicate process (with 9 sprites!) by having just one sprite and everything done automatically.

Thank you Nicki, I will take a look at your work, it could help me! Nice to share :)

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #5 on: December 10, 2013, 05:22:34 AM »
Just to add another reason why tiled-sliced sprites are a good thing compared to the 9 pieces solution, tiled sprites need to have a very weak compression (like 32 bits), or there are artefacts at each repetition of the sprites (when compressed to PVRTC4 for example) ; if only the center of a sprite is tiled, this problem won't show up anymore.

Edit : And even with a 32 bits compression, there are still artefacts when the tiled sprite is used as a image button or when it's dragged... I think I'll go with your solution Nicki (I think it will fix all this), but it would have been better if it was included in the officiel package for the updates.
« Last Edit: December 10, 2013, 06:11:36 AM by Grhyll »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #6 on: December 10, 2013, 07:03:04 AM »
Score 1 for me. :P

Just make sure you don't use too small tiles, since there's no sanity check on the code - it will make however many vertices it needs, which can become quite a lot.

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #7 on: December 10, 2013, 08:07:45 AM »
Thanks for the advice, did not think of that!

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #8 on: December 10, 2013, 11:19:51 AM »
I have been trying many different solutions for this issue today, and this advanced sprite script (with a few modification to adapt it to current NGUI version) is by far the best : the most simple and with the nicest results.  I definitely think it should be in the release version :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #9 on: December 10, 2013, 09:46:14 PM »
Well, if Nicki submits a pull request for it in the latest version, I'll have a look ;)

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #10 on: December 11, 2013, 04:09:14 AM »
He just might. ;)

Grhyll

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: Tiled-sliced sprite ?
« Reply #11 on: December 11, 2013, 09:14:45 AM »
Great! Thanks :)