RT @IamDeanTate: I'm tweeting this now because I just did a lot of work & it's the middle of the night & no-one will see this. t.co… (Today)

@psysal People are all bout the one punch man these days (Today)

@shaneneville @ChevyRay the three pillars of happiness (Yesterday)

RT @infinite_ammo: I'm doing the music for Moonlighter, a rad game that is coming to Kickstarter in a few days! t.co/CvA1JjnrZ3 htt… (Yesterday)

@gertjanstolk that would be cool as heck. Can get me at hi@kpulv.com (Yesterday)

@codeapparat Hmm okay, there's BufferData, but now how to convert any of that to color data o __ o (2 days ago)

@codeapparat Hmm right but how do I get such an array from SharpFont's bitmaps? (2 days ago)

So I'm using System.Drawing.Bitmap as part of the process to Texture2D here, but I'm thinking this might not be the best idea... (2 days ago)

Yeeehaw loadin' a whole font into FNA with SharpFont t.co/TJfjxY1MPs (2 days ago)

@AsherVo making video games is like 10% game stuff and 173% UI design and programming (2 days ago)

RT @tripleboop: 3v3 tourney for #towerfall at 3B: t.co/KevlbepVWw cc @kylepulver @MattThorson etc rt rt rt (2 days ago)

@ChevyRay @eigenbom I have a W showing up for now #blessed t.co/0RzVOwdYCn (2 days ago)

@ChevyRay @eigenbom Ohh I was looking at the font code you gave me for SDL2 as a reference... but maybe we shall chat again soooon <3 (2 days ago)

@eigenbom eh maybe if I was doing 3d, I've given it a few shots and I just don't like the feel of the workflow for 2d :I (2 days ago)

@eigenbom Sort of. A lot of my utility/helper stuff is instant portable. Rebuilding the rendering stuff though using old code as a guide. (2 days ago)

@eigenbom UHHhhh trying to figure out if FNA is gonna be usable for my next project. Right now I am in font/text rendering hell. ;D (2 days ago)

Okay lets try to take this SharpFont library and uhh somehow... render text with XNA... and uh... *barf* (3 days ago)

@jacobalbano I compiled my .fx file into a .fxb with that fxc.exe program from the direct x SDK. Can be just used on its own. (3 days ago)

this may just look like a pink silhouetted graphic but it represents a shader actually working with FNA yeehaaawww t.co/AbriJFfgA5 (3 days ago)

@flibitijibibo Probably best thing is on google chats pulverk@gmail.com (3 days ago)

follow
search

2013 - 3 - 6 / 2:14 pm / general

A Flashpunk 9-Slice Object

A Flashpunk 9-Slice Object

As I've been working on this Global Game Jam game remake, I've been trying to come up with solutions for problems that I can hopefully reuse for more projects in the future. One of the things I've been thinking a lot about is managing and drawing the various user interfaces for the game. Even though I'm not quite sure how much UI stuff this game will need, I wanted to have some sort of solid base to start with so that I could get stuff up and running quickly.

One of the most basic core structures of drawing a cool UI (in my opinion!) is a 9-slice graphic object. What's a 9-slice graphic object?! Well, here's a quick example of one that I have working in Flashpunk right now.

Image
The box that is being drawn above the red player rectangle is a working example of my NineSlice class. It's being drawn from a source image of nine tiles. The source file has four tiles for the corners, four tiles for the sides, and one tile for the center. Here's what the source looks like (blown up 4x because it is tiny.)

Image
This is incredibly useful because it's now possible for me to draw stylized boxes for potential UI components at any size without having to draw each one individually. One thing that I wish that I had spent more time on in Offspring Fling is the UI for the menus, so in the future I want to make my menus and interfaces as awesome as they can be, and having some functions do a lot of the fancy work for me is a big step in that direction. Here's what it looks like right now: NineSlice.as

Here are some snippets of code from the example shown above:

//initial set up
private var nineSliceTest:NineSlice = new NineSlice(Assets.IMG_NINE_SLICE_TEST, 3, 3, 3, 3);
//in the entity's constructor
nineSliceTest.scrollX = nineSliceTest.scrollY = 0;
nineSliceTest.width = 40;
nineSliceTest.height = 40;
nineSliceTest.x = 50;
nineSliceTest.y = 50;
//in the entity's render function
nineSliceTest.render();

Right now this is a very rough first pass on this kind of thing. Ideally it would be some sort of Flashpunk graphic extension that would plug directly into the Flashpunk rendering system. For now it makes use of the Flashpunk Draw class, and some utility functions that I've written for myself. Feel free to use it or improve it, and if you end up improving it then let me know!

2 Comments
Avatar

2013 - 3 - 11 3:45 PM

fedyfausto

excuse me but i see a diagonal tile how can i dothat in FP?

Avatar

2013 - 3 - 11 8:02 PM

Kyle

I posted about slopes a few weeks ago, if you just go back through the posts in February you'll find some info about that.

Avatar

Post your comment!

POST COMMENT

about

About

Hi! My name's Kyle, and I make video games most of the time in Denver, Colorado. Here you will find my thoughts, games, websites, doodles, and other stuff like that. I worked on Snapshot, Offspring Fling, and a whole bunch of other games. I also created and maintain Otter, a 2d game making framework. If you want to get a hold of me use the form on the bottom of the page, leave a comment, or just tweet at me. I try to post three times a week. Thanks for stoppin' by! You're the coolest.

blog stuff

categories

tags

archives

facebook

videos

Do you want to make a Let's Play of one of my games, or a just a video featuring footage of my games? You have my full permission to do so! Even if you are monetizing your videos, you still have my full permission to use any footage from any of my games. Go for it!

contact

Your message has been sent! Thanks :)
SEND MESSAGE