SHSplashScreen

type:
extension
author:
Shilo White
description:
A simple splash screen.
lastupdate:
2011-03-26
compatible:
v1.X
tag:
splash, splashscreen, advertisement, logo
homepage:
https://gist.github.com/888135
download:
https://gist.github.com/gists/888135/download
sample:
http://shilo.coarsemode.com/sparrow/extensions/shsplashscreen/SplashScreenSample.zip

Description

SHSplashScreen class will allow you to create splash screens with only a few lines of code. You can set the start/end transitions, start/end transition times, idle time, and you can toggle on/off skipOnTouch or transitionOnTouch. This extension subclasses SPSprite, so you can add anything to the splash screen, whether it would be an image, movieclip, or other.

Sample

Example

//initialize the splash screen with an idle time of 5.0f and default transitions
SHSplashScreen *splashScreen = [SHSplashScreen splashScreenWithTime:5.0f];
 
//initialize and add an image to the splash screen
SPImage *logo = [SPImage imageWithContentsOfFile:@"logo.png"];
[splashScreen addChild:logo];
 
//add the splash screen to the stage, it will automatically start and automatically remove itself from the stage when finished.
[self addChild:splashScreen];

Documentation

Instructions

To add into your Sparrow project

  1. Download the source files here: https://gist.github.com/gists/888135/download
  2. Open your desired Sparrow project
  3. Drag and drop the files into the “Groups & Files” pane
  4. Open “Game.h”
  5. Include the extension:
    #include "SHSplashScreen.h"
  6. Save “Game.h”

To add directly into Sparrow source

  1. Download the source files here: https://gist.github.com/gists/888135/download
  2. Save the files into Sparrow's “/Classes/” directory
    • Example: “/sparrow/src/Classes/”
  3. Navigate back one directory and open “Sparrow.xcodeproj”
    • Example: “/sparrow/src/Sparrow.xcodeproj”
  4. Inside the “Groups & Files” pane, locate the “Display” group folder
    • Example: “Sparrow → Classes → Display”
  5. Right click the “Display” group folder and click “Add → Existing Files..”
  6. Navigate into the “/Classes/” directory and select “SHSplashScreen.h” and “SHSplashScreen.m”, then click “add”
  7. On the next window, leave all options as default and click “add”
  8. In the “Groups & Files” pane, Open “Sparrow.h”
    • Example “Sparrow → Classes → Sparrow.h”
  9. At the bottom of the file, add:
    #import "SHSplashScreen.h"
  10. Save “Sparrow.h”
  11. Close “Sparrow.xcodeproj”

Source Code

Changelog

  • 2011-03-25: First version

Todo

  • (EMPTY)

API Reference

Inherits from SPSprite : SPDisplayObjectContainer : SPDisplayObject : SPEventDispatcher : NSObject
Declared in SHSplashScreen.h

Overview


SHSplashScreen will function similar to a SPSprite. After initializing, you can add children to the splash screen. Once you add the splash screen to the stage, it will automatically began the transitions. After the splash screen finishes the end transition, it will remove itself from the stage. You can set skipOnTouch or transitionOnTouch to allow users to end the splash screen on touch. You can also listen to each phase of the splash screen by listening to event type SH_EVENT_TYPE_SPLASH_SCREEN, see Events for more detail.

Instance Methods


init

Returns an initialized SHSplashScreen object that contains default properties.

- (id)init

initWithTime:

Returns an initialized SHSplashScreen object that contains default properties and sets the idle time given, in seconds.

- (id)initWithTime:(float)time


Class Methods


splashScreen

Returns an auto-released initialized SHSplashScreen object that contains default properties.

+ (SHSplashScreen *)splashScreen

splashScreenWithTime:

Returns an auto-released initialized SHSplashScreen object that contains default properties and sets the idle time given, in seconds.

+ (SHSplashScreen *)splashScreenWithTime:(float)time


Properties


startTransition

The start transition as SHSplashScreenTransition. See Constants for more detail.

@property (nonatomic, assign) SHSplashScreenTransition startTransition

Default Value
SHSplashScreenTransitionFade

endTransition

The end transition as SHSplashScreenTransition. See Constants for more detail.

@property (nonatomic, assign) SHSplashScreenTransition endTransition

Default Value
SHSplashScreenTransitionFade

time

The idle time in seconds, which is after the start transition and before the end transition.

@property (nonatomic, assign) float time

Default Value
2.0f

startTransitionTime

The start transition time in seconds, which is before the idle time.

@property (nonatomic, assign) float startTransitionTime

Default Value
0.5f

endTransitionTime

The end transition time in seconds, which is after the idle time.

@property (nonatomic, assign) float endTransitionTime

Default Value
0.5f

skipOnTouch

Indicates if the splash screen will immediately end and be removed from the stage when the stage is touched.

@property (nonatomic, assign) BOOL skipOnTouch

Default Value
NO

transitionOnTouch

Indicates if the splash screen will begin the end transition when the stage is touched.

@property (nonatomic, assign) BOOL transitionOnTouch

Default Value
YES

Constants


SHSplashScreenTransition

The transition for either the start transition or the end transition.

typedef enum {
        SHSplashScreenTransitionFade,
        SHSplashScreenTransitionZoom,
        SHSplashScreenTransitionSlideUp,
	SHSplashScreenTransitionSlideDown,
	SHSplashScreenTransitionSlideLeft,
	SHSplashScreenTransitionSlideRight,
	SHSplashScreenTransitionFadeUp,
	SHSplashScreenTransitionFadeDown,
	SHSplashScreenTransitionFadeLeft,
	SHSplashScreenTransitionFadeRight,
	SHSplashScreenTransitionZoomUp,
	SHSplashScreenTransitionZoomDown,
	SHSplashScreenTransitionZoomLeft,
	SHSplashScreenTransitionZoomRight
} SHSplashScreenTransition;

SHSplashScreenTransitionFade

  • A fade transition. The start transition will increment the alpha value from 0 to 1.0. The end transition will increment the alpha value from 1.0 to 0.

SHSplashScreenTransitionZoom

  • A zoom transition from the center of the screen. The start transition will increment the scale value from 0 to 1.0 and position the splash screen to the center of the screen while transitioning. The end transition will increment the scale value from 1.0 to 0 and position the splash screen to the center of the screen.

SHSplashScreenTransitionSlideUp

  • A slide transition in an upwards motion. The start transition will increment the y value from the bottom of the screen to 0. The end transition will increment the y value from 0 to -height.

SHSplashScreenTransitionSlideDown

  • A slide transition in a downwards motion. The start transition will increment the y value from the -height to 0. The end transition will increment the y value from 0 to the bottom of the screen.

SHSplashScreenTransitionSlideLeft

  • A slide transition in an leftwards motion. The start transition will increment the x value from the far-right of the screen to 0. The end transition will increment the x value from 0 to -width.

SHSplashScreenTransitionSlideRight

  • A slide transition in a rightwards motion. The start transition will increment the x value from the -width to 0. The end transition will increment the x value from 0 to the far-right of the screen.

SHSplashScreenTransitionFadeUp

  • A slide transition in an upwards motion while fading. The start transition will increment the y value from the bottom of the screen to 0 while incrementing the alpha value from 0 to 1.0. The end transition will increment the y value from 0 to -height while incrementing the alpha value from 1.0 to 0.

SHSplashScreenTransitionFadeDown

  • A slide transition in a downwards motion while fading. The start transition will increment the y value from the -height to 0 while incrementing the alpha value from 0 to 1. The end transition will increment the y value from 0 to the bottom of the screen while incrementing the alpha value from 1.0 to 0.

SHSplashScreenTransitionFadeLeft

  • A slide transition in an leftwards motion while fading. The start transition will increment the x value from the far-right of the screen to 0 while incrementing the alpha value from 0 to 1.0. The end transition will increment the x value from 0 to -width while incrementing the alpha value from 1.0 to 0.

SHSplashScreenTransitionFadeRight

  • A slide transition in a rightwards motion while fading. The start transition will increment the x value from the -width to 0 while incrementing the alpha value from 0 to 1.0. The end transition will increment the x value from 0 to the far-right of the screen while incrementing the alpha value from 1.0 to 0.

SHSplashScreenTransitionZoomUp

  • A slide transition in an upwards motion while zooming. The start transition will increment the y value from the bottom of the screen to 0 while scaling from 0 to 1.0. The end transition will increment the y value from 0 to -height while scaling from 1.0 to 0.

SHSplashScreenTransitionZoomDown

  • A slide transition in a downwards motion while zooming. The start transition will increment the y value from the -height to 0 while scaling from 0 to 1.0. The end transition will increment the y value from 0 to the bottom of the screen while scaling from 1.0 to 0.

SHSplashScreenTransitionZoomLeft

  • A slide transition in an leftwards motion while zooming. The start transition will increment the x value from the far-right of the screen to 0 while scaling from 0 to 1.0. The end transition will increment the x value from 0 to -width while scaling from 1.0 to 0.

SHSplashScreenTransitionZoomRight

  • A slide transition in a rightwards motion while zooming. The start transition will increment the x value from the -width to 0 while scaling from 0 to 1.0. The end transition will increment the x value from 0 to the far-right of the screen while scaling from 1.0 to 0.

SHSplashScreenPhase

The current phase/state of the transitions.

typedef enum {    
	SHSplashScreenPhaseBegan,
	SHSplashScreenPhaseStartTransitionEnded,
	SHSplashScreenPhaseEndTransitionBegan,
	SHSplashScreenPhaseEnded,
} SHSplashScreenPhase;

SHSplashScreenPhaseBegan

  • The splash screen has been added to the stage and began the start transition.

SHSplashScreenPhaseStartTransitionEnded

  • The splash screen has completed the start transition and entered the idle state.

SHSplashScreenPhaseEndTransitionBegan

  • The splash screen has completed the idle state and began the end transition.

SHSplashScreenPhaseEndTransitionEnded

  • The splash screen has completed the end transition and will remove itself from stage.

Events


SHSplashScreenEvent

An event that gets dispatched when entering each SHSplashScreenPhase. You can listen to the event with event type SH_EVENT_TYPE_SPLASH_SCREEN.

SHSplashScreen *splashScreen = [SHSplashScreen splashScreen];
[splashScreen addEventListener:@selector(onSplashScreenEvent:) atObject:self forType:SH_EVENT_TYPE_SPLASH_SCREEN];
  users/shilo/extensions/shsplashscreen.txt · Last modified: 2013/03/05 10:19 (external edit)
 
Powered by DokuWiki