Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to make a sprite that scale keeping the border radius?  (Read 1732 times)

0 Members and 1 Guest are viewing this topic.

pavanetti

  • Newbie
  • *
  • Posts: 8
    • View Profile
How to make a sprite that scale keeping the border radius?
« on: September 27, 2011, 01:27:32 am »
I want to make a sprite like these:
http://alignedleft.com/blog/wp-content/uploads/2010/07/Amazing-Button-Active-Border.png
http://alignedleft.com/blog/wp-content/uploads/2010/07/Amazing-Button-Active.png
http://www.ignacioricci.com/tutorials/rounded%20corners/images/tutorial/creating-your-rounded-box-sprite-part2.gif

When I scale the image, only the center is totally scaled. The corners isn't scaled, the horizontal edges is scaled by x factor only and the vertical edges is scaled by y factor only.
How can I make this? Using a class with 4 sprites(one for center, one for corners, one for vertical edges and one for horizontal edges)? :?  :?:

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
How to make a sprite that scale keeping the border radius?
« Reply #1 on: September 27, 2011, 02:56:18 am »
I think you're looking for a simpler version of something like the box model in  web languages.

In your place, I would make your button class with some functions to set this "box model" sprites.

Then, when you need to draw, it should go something like:

- draw corner sprite at button top-left position (pos).
- draw top sprite at pos.x + corner.width and with its width set as button.width-corner.width*2
- draw corner again, rotated.

-draw left sprite at pos.y + corner.height and dimensions as button.height-corner.height*2
-draw center sprite at position (corner.width, corner.height) and set its dimensions to be the same as top sprite for x and left sprite for y.

.. I think you can figure it from now!

Hope i helped and that i got to the point of your question.

 

anything