As a thank you to the folks of this forum I am sharing the first version of an iPhone GUI library. It is inspired by SpriteManager, SpriteUI and GUIManager and borrows some code from each. With all these sprite/GUI options why make another? None of the others did exactly what I wanted. I created the GUISpriteUI library to have an easy, highly efficient way to draw a game HUD and to provide menus between levels and on start up. GUISpriteUI uses no collections classes and uses standard arrays for all data. GUISpriteUI also makes it easy to get your HUD setup with code that makes sense from the start.
GUISpriteUI comes prepackaged with the following elements:
GUISprite: standard sprite object
GUISpriteButton: standard button with highlighted and normal images. Kicks off a delegate when touched
GUISpriteToggleButton: 3 state toggle button (checkbox). Sends a delegate function when changed as well
GUIKnob: volume control-like know with a highlighted and normal state. Can send events continuously (every touchesMoved) or only onTouchesEnded
GUISlider: horizontal or vertical slider that can send events continuously or only onTouchesEnded
GUIProgressBar:: progress bar or health meter. The 'bar' portion of the element can be either stretched or only a portion of the image used when it is less than full (see the demo. It toggles between stretched and normal)
GUIJoystick: fully customizable joystick and optional background image that hangs out behind the joystick
GUISwipeDetector: detects swipes in all 4 directions or any combination of them inside the given rectangle.
GUISpriteUI lets you create your own GUITouchableSprite subclasses so that you can make any UI object that you need and it will work seamlessly with the rest of the library.
Each touchable sprite can have it's touch area set to an area smaller or larger than it's size. You can also have the touch area be a different size when the element is highlighted. This is useful for sliders and knobs so that your finger doesn't have to be directly on them when sliding around.
The attached package has a fully working scene with all the GUISpriteUI UI elements so you can see how to set everything up. For new project setup just follow the included read me.
Here are a few samples of a few elements so you can see how easy it is to use GUISpriteUI:
Code:
// Create a button at the point 10, 10 from the top-left corner of the screen that is 108 px wid and 37 px high // UVRect defines the pixel location on your texture map the graphic to use for this button GUISpriteButton playButton = GUISpriteUI.instance.addSpriteButton( new Rect( 10, 10, 108, 37 ), 3, new UVRect( 0, 0, 108, 37, textureSize ) ); // Optional: Add a different graphic for the highlighted state playButton.highlightedUVframe = new UVRect( 0, 37, 108, 37, textureSize );
Code:
// Expand our highlighted touch area 30 pixels all around // When the button is touched, this function will be called // Set the opacity to 0.5 for this button
Code:
// Horizontal Slider. Be sure to offset the sliderKnobs Y value to line it up properly GUISprite hSliderKnob = GUISpriteUI.instance.addSprite( new Rect( 20, 245, 30, 50 ), new UVRect( 120, 130, 30, 50, textureSize ), 1 ); GUISlider hSlider = new GUISlider( new Rect( 20, 250, 200, 40 ), 2, new UVRect( 120, 80, 200, 40, textureSize ), hSliderKnob, onHSliderChanged ); GUISpriteUI.instance.addTouchableSprite( hSlider ); // Increase our hit area a bit while we are tracking along the slider hSlider.highlightedTouchOffsets = new GUIEdgeOffsets( 20, 30, 20, 30 ); hSlider.value = 0.2f;
Example animation call:
Code:
GUISpriteUI.instance.to( sprite, duration, GUIAnimationProperty.EulerAngles, to, Easing.Sinusoidal.factory(), Easing.EasingType.Out );
A more complicated animation that pulses the alpha of an element from 0.1 to 1.0 would be:
Code:
private IEnumerator pulseOptionButton( GUISpriteButton optionsButton ) { GUIAnimation ani; while( true ) { ani = GUISpriteUI.instance.to( optionsButton, 0.7f, GUIAnimationProperty.Alpha, 0.1f, Easing.Linear.factory(), Easing.EasingType.In ); yield return ani.chain(); ani = GUISpriteUI.instance.to( optionsButton, 0.7f, GUIAnimationProperty.Alpha, 1.0f, Easing.Linear.factory(), Easing.EasingType.Out ); yield return ani.chain(); } } // Start pulsing a button
All animation routines allow you chain them by just yieding the chain() method. This will return a WaitForSeconds of the amount of time remaining in the animation.

Reply With Quote