SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
Developing a videogame with
         Titanium Appcelerator
  Creating a simple game is a fun way to start learning the Titanium
                           Appcelerator APIs




alessio.ricco@gmail.com
Appcelerator: Native Development
Native development
Easy to use
Multiplatform (iOS/Android/Blackberry (very soon))
Javascript
Extensible with modules
Analytics
Social Networks API (twitter, facebook, foursquare, yahoo)
Complete native API and controls coverage
Full HTML5 and CSS3 support
Rich Media and Device Capabilities Supported
… and videogames ?
GoLingo -- http://www.golingoapp.com/
SwarmSG -- http://swarmsg.com/
NeighborSmash -- http://enbo.pl/titanium/neighbour-smash.zip
BustinOut -- http://boydlee.com/assets/bustinout/app.js

… and …


TwinsMatcher
  (http://itunes.apple.com/us/app/twinsmatcher/id429890747?mt=8)
TwinsMatcher: Features
Built with Titanium Appcelerator in 2 weeks.
main features:

-   handmade ugly graphics
-   timers
-   custom fonts
-   facebook and twitter integration
-   music and sound effects
-   simple animations
-   iAd
-   database (sqlite)
-   gestures (shake)
TwinsMatcher: Game Rules
250 seconds to clear a
12x9 board full of icons

touch an icon and its twin
to make them disappear

the icons must be adjacent or
separated by empty spaces

shaking your device will shuffle the icons
TwinsMatcher: the flow
TwinsMatcher: the files structure
TwinsMatcher: App.js
app.js is your application's root execution context
app.js serves as the entry point for your application.
app.js is the best candidate for init code

//   DEFINE CONST AND GLOBAL VARS
//   INIT DATABASE
//   INIT MUSIC FILES
//   INIT APPLICATION WINDOWS
//   DEFINE APPLICATION EVENTS
//   SHOW THE MAIN WINDOW
TwinsMatcher: Win,View & ...
The following are the major design components
in Titanium:
Windows     host one or more Views
Views       draw content on the screen
Widgets     are special types of views
            that perform specific actions
            like buttons
var win = Ti.UI.createWindow();
var view = Ti.UI.createImageView({
  image:"myimage.png",
  width:24,
  height:24
});
win.add(view);
win.open();
Appcelerator: factory pattern
Titanium's UI APIs have a factory-style interface
Ti.UI.createView({
    height:400,
    backgroundColor:'red'
});




When creating your own functions, you might want to take this convention one step further by adding the
Titanium 'base' class to the end of your component type. So you might have function names that follow
the convention "create"+business view type+Titanium base component:

e.g. : createMainApplicationWindow
TwinsMatcher: Game.js
The gameplay is managed handling 5 events:

on window load: initialize game structures and components

on window focus: arrange the icons, paint the board, start the game

on windows click: manage icons selection

on shake event: shuffle the icons

timer: check if the available time expired, if so the game ends
TwinsMatcher: ingredients
A View containing the icons (vBoard)
A 12x9 matrix of game icons (preloaded)
A 12x9 matrix of selection icons (preloaded)

preloaded sounds and icons to prevent
   memory leaks

A quick shuffle algorithm
A quick path finder algorithm

A great graphic designer !
TwinsMatcher: how to draw
no need to draw, everything is done “programmatically”


function initIcons() {
   icons = new Array( MAXROW );
   for( var r = 0; r < MAXROW; r ++ ) {
      icons [ r ] = new Array( MAXCOL );
      var rr = getRowPixel( r );
      for( var c = 0; c < MAXCOL; c ++ ) {
         var cc = getColPixel( c );
         icons [ r ][ c ] = buildIcon( "path", rr, cc );
         vBoard.add( icons [ r ][ c ] );// add icon to view
...(to be continued)...
TwinsMatcher: how to draw
ImageView Factory call example (board icons)


function buildIcon( url, top, left ) {
    var icon = Titanium.UI.createImageView( {
                    image : getIcon( url ),
                    width : iconW,
                    height : iconH,             c	
  
                    top : top,
                    left : left,
                    visible:false
             } );
    return icon;
}
TwinsMatcher: how to draw
// Create SCORE label
var lblScore = Titanium.UI.createLabel( {
   text : '0',
   color : textColor,
   font: labelFontBig,
   top : 2,
   height : labelFontBig.fontSize + 8,
   left : LEFTPOS,
    width : WIDTHPOS
} );
// Add SCORE label to the board
vBoard.add( lblScore );
TwinsMatcher: how to play sounds
1) Initializing sound in app.js

2) Playing background music

3) Assign the music array as window parameter

4) Play/Stop sound when it's needed
TwinsMatcher: init sounds
// sound files array
var soundfiles=["sound/click.mp3", …,"sound/bgmusic.mp3"];
// build sound object (preload at inizialization)
var soundmusic = [ ];
for( var sf in soundfiles ) {
    soundmusic.push(
    Ti.Media.createSound( {
    sound :       Titanium.Filesystem.getFile
    ( Titanium.Filesystem.resourcesDirectory, soundfiles [ sf ] ),
    preload : true } ) );
}
// play background music in loop
soundmusic[SOUND_MUSIC].setVolume(MUSIC_VOLUME);
soundmusic[SOUND_MUSIC].play();
soundmusic[SOUND_MUSIC].looping = true;
TwinsMatcher: stop music
function stopMusic (i) {
     // get current window
     var win = Titanium.UI.currentWindow;
     if (win == null) {return;};
     // sound array
     sound = win.sound;
     // stop music
     sound[i].stop();
}
TwinsMatcher: onClick
window click event is used to find the icon coordinates on the board


win.addEventListener( “click”, function( e ) {
   ...
   var x = e.source.left + 5; // click event property
   var y = e.source.top + 5;      // click event property
   var r = parseInt( getRow( y ) , 10 ); // board coordinate
   var c = parseInt( getCol( x ) , 10 ); // board coordinate
   if( board [ r ][ c ]== null ) { return; } // no icons
   if( choiceIndex == - 1 ) { // no other icon selected
         playSound( SOUND_ONCLICK1 ); // click sound
         doSelectIcon( r, c );   // show the icon as “selected”
         return;
   }
   ...(to be continued)...
TwinsMatcher: onClick
function onIconsSelected( ) {
…
// verify the clicked icons: are they of the same kind?
if(( sameKindOfIcon( r0,c0,r1,c1 )) {
// find a path between the icons
var path = pathFinder( r0, c0, r1, c1 );
if( path != null ) {
    // GREAT !
    onShowPath( path, r0, c0 );
    // update score, remove the icons
    ...
} else {
lblTips.text = "Can't find a path";
playSound( SOUND_ONPATHNOTFOUND );
}
} else ...
TwinsMatcher: Animation
function onShowPath( path, r0, c0 ) {
playSound( SOUND_ONPATH );
// show the path between twins
for( var o in path ) {
      var icon = icons [ path [ o ].r ]
                         [ path [ o ].c ];
      icon.image = getIcon(board [ r0 ][ c0 ] );
      icon.visible = true;};
// remove icons on timeout
setTimeout(function() {
    for( var o in path ) {
          var icon = icons [ path [ o ].r ]
                             [ path [ o ].c ];
          removeIcon( icon );    }
    onCheckEndGame( );
},100);
}
TwinsMatcher: database init
SQLite3 is version 3 of SQLite's SQL-based relational database management system
    (RDMS), chosen by Apple, Google and RIM to provide local data storage on their
    mobile devices.


App.js
var db = Titanium.Database.open( 'twinsmatcher.db3' );
if (db == null) {
Ti.API.info("cannot open db");
} else {
var result = db.execute('CREATE TABLE IF NOT EXISTS [score] ( id
   INTEGER PRIMARY KEY AUTOINCREMENT, [created] TIMESTAMP DEFAULT
   (0), [level] BIGINT DEFAULT (0), [score] BIGINT DEFAULT
   (0));');
}
TwinsMatcher: db.execute
function setScore(level, score) {
    var result = db.execute( "insert into score(level,score,created ) values
    ( ?,?,? )", level,score, fetch_unix_timestamp( ));
}


function getScore(level) {
    ...
    rows = db.execute( "select    max(score) as maxscore from score where
    level=?", level );
    if( rows.isValidRow( )) {    score= rows.field( 0 ) }
    ...
    rows.close( );
    ...
    return score;
}
TwinsMatcher: iAd
function iAdWindow(win) {
     iads = Ti.UI.iOS.createAdView({
      width : 'auto',
      height : 'auto',
      bottom : - 100,
      zindex : 100,
      borderColor : '#fff',
      backgroundColor : '#fff'});
     iads.addEventListener( 'load', function( ) {
       var t1 = Titanium.UI.createAnimation( { bottom : 0, duration : 750 } );
       iads.animate( t1 );
     } );
     iads.addEventListener( 'error', function() {
        win.remove(iads);
     } );
    win.add( iads );
}
TwinsMatcher: Custom Fonts
Example in settings.js
var musicSwitchLabel = Titanium.UI.createLabel( {
      text: “background music”
      font : { fontFamily : “customfont.otf”,
                 fontSize : 28 };,
...
} );
win.add( musicSwitchLabel );


info.plist must be customized and placed in the project root
<key>UIAppFonts</key>
<array>
<string>customfont.otf</string>
</array>
TwinsMatcher: Twitter
oauth-adapter by David Riccitelli
Provides a JavaScript library for use within Appcelerator Titanium
   mobile (iPhone, iPad, ...) projects in order to establish OAuth
   protocol-based communications to services such as Twitter.

http://code.google.com/p/oauth-adapter/

var btTweeter = createButton(TOP,"tweetScore");
btTweeter.addEventListener('click', function(){
   var tweet = makeTwitterStatus( shareMessage(), '' ) //message
   twitter( tweet );
});
win.add( btTweeter );
TwinsMatcher: Facebook
var btFacebook = createButton(TOP,"facebookScore");
// open feed publish dialog if clicked
btFacebook.addEventListener('click', function()
{
var data = {
      link: APPSHORTURL,        // link to appStore
      name: customer_name,
      message: shareMessage(), // message to publish
      caption: customer_name,
      picture: app_logo,        // app icon url
      description: APP_DESC
};
Titanium.Facebook.dialog("feed", data, FBshowRequestResult);
});
win.add( btFacebook );
}
TwinsMatcher: Facebook login

           var fbButton =
           Titanium.Facebook.
             createLoginButton({
               style:'wide',
               top:TOP,
               height:30,
               width:300
           });
           win.add(fbButton);
Thank you !
TwinsMatcher is available on AppStore
http://itunes.apple.com/us/app/twinsmatcher/id429890747?mt=8



concept by alessio ricco

developed by emanuele fusco and alessio ricco




info and contacts: alessio.ricco@gmail.com

Mais conteúdo relacionado

Mais procurados

Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing UsYegor Bugayenko
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your appsJuan C Catalan
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185Mahmoud Samir Fayed
 
Mobile And The Latency Trap
Mobile And The Latency TrapMobile And The Latency Trap
Mobile And The Latency TrapTom Croucher
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabScilab
 
Crush Candy with DukeScript
Crush Candy with DukeScriptCrush Candy with DukeScript
Crush Candy with DukeScriptAnton Epple
 

Mais procurados (7)

Utility Classes Are Killing Us
Utility Classes Are Killing UsUtility Classes Are Killing Us
Utility Classes Are Killing Us
 
pptuni1
pptuni1pptuni1
pptuni1
 
Adopting 3D Touch in your apps
Adopting 3D Touch in your appsAdopting 3D Touch in your apps
Adopting 3D Touch in your apps
 
The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185The Ring programming language version 1.5.4 book - Part 46 of 185
The Ring programming language version 1.5.4 book - Part 46 of 185
 
Mobile And The Latency Trap
Mobile And The Latency TrapMobile And The Latency Trap
Mobile And The Latency Trap
 
How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in Scilab
 
Crush Candy with DukeScript
Crush Candy with DukeScriptCrush Candy with DukeScript
Crush Candy with DukeScript
 

Semelhante a Writing videogames with titanium appcelerator

Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersAmbarish Hazarnis
 
Kotlin Mullets
Kotlin MulletsKotlin Mullets
Kotlin MulletsJames Ward
 
[1D6]RE-view of Android L developer PRE-view
[1D6]RE-view of Android L developer PRE-view[1D6]RE-view of Android L developer PRE-view
[1D6]RE-view of Android L developer PRE-viewNAVER D2
 
What's great in Appcelerator Titanium 0.8
What's great in Appcelerator Titanium 0.8What's great in Appcelerator Titanium 0.8
What's great in Appcelerator Titanium 0.8Jeff Haynie
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfShaiAlmog1
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentanistar sung
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to CodingFabio506452
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxyginecorehard_by
 
An introduction to the create js suite
An introduction to the create js suiteAn introduction to the create js suite
An introduction to the create js suiteScott Ackerman
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of usOSCON Byrum
 
There's more than web
There's more than webThere's more than web
There's more than webMatt Evans
 
The Ring programming language version 1.5.3 book - Part 15 of 184
The Ring programming language version 1.5.3 book - Part 15 of 184The Ring programming language version 1.5.3 book - Part 15 of 184
The Ring programming language version 1.5.3 book - Part 15 of 184Mahmoud Samir Fayed
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomerzefhemel
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 MinigamesSusan Gold
 
Criando jogos para o windows 8
Criando jogos para o windows 8Criando jogos para o windows 8
Criando jogos para o windows 8José Farias
 

Semelhante a Writing videogames with titanium appcelerator (20)

Titanium Appcelerator - Beginners
Titanium Appcelerator - BeginnersTitanium Appcelerator - Beginners
Titanium Appcelerator - Beginners
 
Kotlin Mullets
Kotlin MulletsKotlin Mullets
Kotlin Mullets
 
mobl
moblmobl
mobl
 
[1D6]RE-view of Android L developer PRE-view
[1D6]RE-view of Android L developer PRE-view[1D6]RE-view of Android L developer PRE-view
[1D6]RE-view of Android L developer PRE-view
 
What's great in Appcelerator Titanium 0.8
What's great in Appcelerator Titanium 0.8What's great in Appcelerator Titanium 0.8
What's great in Appcelerator Titanium 0.8
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
CreateJS
CreateJSCreateJS
CreateJS
 
C++ game development with oxygine
C++ game development with oxygineC++ game development with oxygine
C++ game development with oxygine
 
Windows Phone Launchers and Choosers
Windows Phone Launchers and ChoosersWindows Phone Launchers and Choosers
Windows Phone Launchers and Choosers
 
An introduction to the create js suite
An introduction to the create js suiteAn introduction to the create js suite
An introduction to the create js suite
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
There's more than web
There's more than webThere's more than web
There's more than web
 
The Ring programming language version 1.5.3 book - Part 15 of 184
The Ring programming language version 1.5.3 book - Part 15 of 184The Ring programming language version 1.5.3 book - Part 15 of 184
The Ring programming language version 1.5.3 book - Part 15 of 184
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
 
shiny_v1.pptx
shiny_v1.pptxshiny_v1.pptx
shiny_v1.pptx
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
Criando jogos para o windows 8
Criando jogos para o windows 8Criando jogos para o windows 8
Criando jogos para o windows 8
 

Mais de Alessio Ricco

Co-design tools and techniques - world usability day rome 2015
Co-design tools and techniques - world usability day rome 2015Co-design tools and techniques - world usability day rome 2015
Co-design tools and techniques - world usability day rome 2015Alessio Ricco
 
Mobile1st ux/ui with Titanium
Mobile1st ux/ui with TitaniumMobile1st ux/ui with Titanium
Mobile1st ux/ui with TitaniumAlessio Ricco
 
Fifty shades of Alloy - tips and tools for a great Titanium Mobile development
Fifty shades of Alloy - tips and tools for a great Titanium Mobile developmentFifty shades of Alloy - tips and tools for a great Titanium Mobile development
Fifty shades of Alloy - tips and tools for a great Titanium Mobile developmentAlessio Ricco
 
Il lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppo
Il lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppoIl lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppo
Il lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppoAlessio Ricco
 
Ti.conf titanium on firefoxos
Ti.conf titanium on firefoxosTi.conf titanium on firefoxos
Ti.conf titanium on firefoxosAlessio Ricco
 
Titanium Mobile and Beintoo
Titanium Mobile and BeintooTitanium Mobile and Beintoo
Titanium Mobile and BeintooAlessio Ricco
 
Titanium appcelerator sdk
Titanium appcelerator sdkTitanium appcelerator sdk
Titanium appcelerator sdkAlessio Ricco
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practicesAlessio Ricco
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first appAlessio Ricco
 
Titanium appcelerator kickstart
Titanium appcelerator kickstartTitanium appcelerator kickstart
Titanium appcelerator kickstartAlessio Ricco
 
Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Alessio Ricco
 
Un'ora sola ti vorrei
Un'ora sola ti vorreiUn'ora sola ti vorrei
Un'ora sola ti vorreiAlessio Ricco
 
tempi e scaletta presentazione
tempi e scaletta presentazionetempi e scaletta presentazione
tempi e scaletta presentazioneAlessio Ricco
 
Interim presentation GSJ11
Interim presentation GSJ11Interim presentation GSJ11
Interim presentation GSJ11Alessio Ricco
 
documentazione e presentazione GSJ11 1/4
documentazione e presentazione GSJ11 1/4documentazione e presentazione GSJ11 1/4
documentazione e presentazione GSJ11 1/4Alessio Ricco
 

Mais de Alessio Ricco (16)

Co-design tools and techniques - world usability day rome 2015
Co-design tools and techniques - world usability day rome 2015Co-design tools and techniques - world usability day rome 2015
Co-design tools and techniques - world usability day rome 2015
 
Mobile1st ux/ui with Titanium
Mobile1st ux/ui with TitaniumMobile1st ux/ui with Titanium
Mobile1st ux/ui with Titanium
 
Fifty shades of Alloy - tips and tools for a great Titanium Mobile development
Fifty shades of Alloy - tips and tools for a great Titanium Mobile developmentFifty shades of Alloy - tips and tools for a great Titanium Mobile development
Fifty shades of Alloy - tips and tools for a great Titanium Mobile development
 
Il lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppo
Il lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppoIl lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppo
Il lato oscuro della forza - L'eterna lotta tra progettisti e team di sviluppo
 
Ti.conf titanium on firefoxos
Ti.conf titanium on firefoxosTi.conf titanium on firefoxos
Ti.conf titanium on firefoxos
 
Titanium Mobile and Beintoo
Titanium Mobile and BeintooTitanium Mobile and Beintoo
Titanium Mobile and Beintoo
 
Titanium appcelerator sdk
Titanium appcelerator sdkTitanium appcelerator sdk
Titanium appcelerator sdk
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
Titanium appcelerator my first app
Titanium appcelerator my first appTitanium appcelerator my first app
Titanium appcelerator my first app
 
Titanium appcelerator kickstart
Titanium appcelerator kickstartTitanium appcelerator kickstart
Titanium appcelerator kickstart
 
Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator Best Practices in apps development with Titanium Appcelerator
Best Practices in apps development with Titanium Appcelerator
 
Un'ora sola ti vorrei
Un'ora sola ti vorreiUn'ora sola ti vorrei
Un'ora sola ti vorrei
 
tempi e scaletta presentazione
tempi e scaletta presentazionetempi e scaletta presentazione
tempi e scaletta presentazione
 
Interim presentation GSJ11
Interim presentation GSJ11Interim presentation GSJ11
Interim presentation GSJ11
 
documentazione e presentazione GSJ11 1/4
documentazione e presentazione GSJ11 1/4documentazione e presentazione GSJ11 1/4
documentazione e presentazione GSJ11 1/4
 
My personal hero
My personal heroMy personal hero
My personal hero
 

Último

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Writing videogames with titanium appcelerator

  • 1. Developing a videogame with Titanium Appcelerator Creating a simple game is a fun way to start learning the Titanium Appcelerator APIs alessio.ricco@gmail.com
  • 2. Appcelerator: Native Development Native development Easy to use Multiplatform (iOS/Android/Blackberry (very soon)) Javascript Extensible with modules Analytics Social Networks API (twitter, facebook, foursquare, yahoo) Complete native API and controls coverage Full HTML5 and CSS3 support Rich Media and Device Capabilities Supported
  • 3. … and videogames ? GoLingo -- http://www.golingoapp.com/ SwarmSG -- http://swarmsg.com/ NeighborSmash -- http://enbo.pl/titanium/neighbour-smash.zip BustinOut -- http://boydlee.com/assets/bustinout/app.js … and … TwinsMatcher (http://itunes.apple.com/us/app/twinsmatcher/id429890747?mt=8)
  • 4. TwinsMatcher: Features Built with Titanium Appcelerator in 2 weeks. main features: - handmade ugly graphics - timers - custom fonts - facebook and twitter integration - music and sound effects - simple animations - iAd - database (sqlite) - gestures (shake)
  • 5. TwinsMatcher: Game Rules 250 seconds to clear a 12x9 board full of icons touch an icon and its twin to make them disappear the icons must be adjacent or separated by empty spaces shaking your device will shuffle the icons
  • 8. TwinsMatcher: App.js app.js is your application's root execution context app.js serves as the entry point for your application. app.js is the best candidate for init code // DEFINE CONST AND GLOBAL VARS // INIT DATABASE // INIT MUSIC FILES // INIT APPLICATION WINDOWS // DEFINE APPLICATION EVENTS // SHOW THE MAIN WINDOW
  • 9. TwinsMatcher: Win,View & ... The following are the major design components in Titanium: Windows host one or more Views Views draw content on the screen Widgets are special types of views that perform specific actions like buttons var win = Ti.UI.createWindow(); var view = Ti.UI.createImageView({ image:"myimage.png", width:24, height:24 }); win.add(view); win.open();
  • 10. Appcelerator: factory pattern Titanium's UI APIs have a factory-style interface Ti.UI.createView({ height:400, backgroundColor:'red' }); When creating your own functions, you might want to take this convention one step further by adding the Titanium 'base' class to the end of your component type. So you might have function names that follow the convention "create"+business view type+Titanium base component: e.g. : createMainApplicationWindow
  • 11. TwinsMatcher: Game.js The gameplay is managed handling 5 events: on window load: initialize game structures and components on window focus: arrange the icons, paint the board, start the game on windows click: manage icons selection on shake event: shuffle the icons timer: check if the available time expired, if so the game ends
  • 12. TwinsMatcher: ingredients A View containing the icons (vBoard) A 12x9 matrix of game icons (preloaded) A 12x9 matrix of selection icons (preloaded) preloaded sounds and icons to prevent memory leaks A quick shuffle algorithm A quick path finder algorithm A great graphic designer !
  • 13. TwinsMatcher: how to draw no need to draw, everything is done “programmatically” function initIcons() { icons = new Array( MAXROW ); for( var r = 0; r < MAXROW; r ++ ) { icons [ r ] = new Array( MAXCOL ); var rr = getRowPixel( r ); for( var c = 0; c < MAXCOL; c ++ ) { var cc = getColPixel( c ); icons [ r ][ c ] = buildIcon( "path", rr, cc ); vBoard.add( icons [ r ][ c ] );// add icon to view ...(to be continued)...
  • 14. TwinsMatcher: how to draw ImageView Factory call example (board icons) function buildIcon( url, top, left ) { var icon = Titanium.UI.createImageView( { image : getIcon( url ), width : iconW, height : iconH, c   top : top, left : left, visible:false } ); return icon; }
  • 15. TwinsMatcher: how to draw // Create SCORE label var lblScore = Titanium.UI.createLabel( { text : '0', color : textColor, font: labelFontBig, top : 2, height : labelFontBig.fontSize + 8, left : LEFTPOS, width : WIDTHPOS } ); // Add SCORE label to the board vBoard.add( lblScore );
  • 16. TwinsMatcher: how to play sounds 1) Initializing sound in app.js 2) Playing background music 3) Assign the music array as window parameter 4) Play/Stop sound when it's needed
  • 17. TwinsMatcher: init sounds // sound files array var soundfiles=["sound/click.mp3", …,"sound/bgmusic.mp3"]; // build sound object (preload at inizialization) var soundmusic = [ ]; for( var sf in soundfiles ) { soundmusic.push( Ti.Media.createSound( { sound : Titanium.Filesystem.getFile ( Titanium.Filesystem.resourcesDirectory, soundfiles [ sf ] ), preload : true } ) ); } // play background music in loop soundmusic[SOUND_MUSIC].setVolume(MUSIC_VOLUME); soundmusic[SOUND_MUSIC].play(); soundmusic[SOUND_MUSIC].looping = true;
  • 18. TwinsMatcher: stop music function stopMusic (i) { // get current window var win = Titanium.UI.currentWindow; if (win == null) {return;}; // sound array sound = win.sound; // stop music sound[i].stop(); }
  • 19. TwinsMatcher: onClick window click event is used to find the icon coordinates on the board win.addEventListener( “click”, function( e ) { ... var x = e.source.left + 5; // click event property var y = e.source.top + 5; // click event property var r = parseInt( getRow( y ) , 10 ); // board coordinate var c = parseInt( getCol( x ) , 10 ); // board coordinate if( board [ r ][ c ]== null ) { return; } // no icons if( choiceIndex == - 1 ) { // no other icon selected playSound( SOUND_ONCLICK1 ); // click sound doSelectIcon( r, c ); // show the icon as “selected” return; } ...(to be continued)...
  • 20. TwinsMatcher: onClick function onIconsSelected( ) { … // verify the clicked icons: are they of the same kind? if(( sameKindOfIcon( r0,c0,r1,c1 )) { // find a path between the icons var path = pathFinder( r0, c0, r1, c1 ); if( path != null ) { // GREAT ! onShowPath( path, r0, c0 ); // update score, remove the icons ... } else { lblTips.text = "Can't find a path"; playSound( SOUND_ONPATHNOTFOUND ); } } else ...
  • 21. TwinsMatcher: Animation function onShowPath( path, r0, c0 ) { playSound( SOUND_ONPATH ); // show the path between twins for( var o in path ) { var icon = icons [ path [ o ].r ] [ path [ o ].c ]; icon.image = getIcon(board [ r0 ][ c0 ] ); icon.visible = true;}; // remove icons on timeout setTimeout(function() { for( var o in path ) { var icon = icons [ path [ o ].r ] [ path [ o ].c ]; removeIcon( icon ); } onCheckEndGame( ); },100); }
  • 22. TwinsMatcher: database init SQLite3 is version 3 of SQLite's SQL-based relational database management system (RDMS), chosen by Apple, Google and RIM to provide local data storage on their mobile devices. App.js var db = Titanium.Database.open( 'twinsmatcher.db3' ); if (db == null) { Ti.API.info("cannot open db"); } else { var result = db.execute('CREATE TABLE IF NOT EXISTS [score] ( id INTEGER PRIMARY KEY AUTOINCREMENT, [created] TIMESTAMP DEFAULT (0), [level] BIGINT DEFAULT (0), [score] BIGINT DEFAULT (0));'); }
  • 23. TwinsMatcher: db.execute function setScore(level, score) { var result = db.execute( "insert into score(level,score,created ) values ( ?,?,? )", level,score, fetch_unix_timestamp( )); } function getScore(level) { ... rows = db.execute( "select max(score) as maxscore from score where level=?", level ); if( rows.isValidRow( )) { score= rows.field( 0 ) } ... rows.close( ); ... return score; }
  • 24. TwinsMatcher: iAd function iAdWindow(win) { iads = Ti.UI.iOS.createAdView({ width : 'auto', height : 'auto', bottom : - 100, zindex : 100, borderColor : '#fff', backgroundColor : '#fff'}); iads.addEventListener( 'load', function( ) { var t1 = Titanium.UI.createAnimation( { bottom : 0, duration : 750 } ); iads.animate( t1 ); } ); iads.addEventListener( 'error', function() { win.remove(iads); } ); win.add( iads ); }
  • 25. TwinsMatcher: Custom Fonts Example in settings.js var musicSwitchLabel = Titanium.UI.createLabel( { text: “background music” font : { fontFamily : “customfont.otf”, fontSize : 28 };, ... } ); win.add( musicSwitchLabel ); info.plist must be customized and placed in the project root <key>UIAppFonts</key> <array> <string>customfont.otf</string> </array>
  • 26. TwinsMatcher: Twitter oauth-adapter by David Riccitelli Provides a JavaScript library for use within Appcelerator Titanium mobile (iPhone, iPad, ...) projects in order to establish OAuth protocol-based communications to services such as Twitter. http://code.google.com/p/oauth-adapter/ var btTweeter = createButton(TOP,"tweetScore"); btTweeter.addEventListener('click', function(){ var tweet = makeTwitterStatus( shareMessage(), '' ) //message twitter( tweet ); }); win.add( btTweeter );
  • 27. TwinsMatcher: Facebook var btFacebook = createButton(TOP,"facebookScore"); // open feed publish dialog if clicked btFacebook.addEventListener('click', function() { var data = { link: APPSHORTURL, // link to appStore name: customer_name, message: shareMessage(), // message to publish caption: customer_name, picture: app_logo, // app icon url description: APP_DESC }; Titanium.Facebook.dialog("feed", data, FBshowRequestResult); }); win.add( btFacebook ); }
  • 28. TwinsMatcher: Facebook login var fbButton = Titanium.Facebook. createLoginButton({ style:'wide', top:TOP, height:30, width:300 }); win.add(fbButton);
  • 29. Thank you ! TwinsMatcher is available on AppStore http://itunes.apple.com/us/app/twinsmatcher/id429890747?mt=8 concept by alessio ricco developed by emanuele fusco and alessio ricco info and contacts: alessio.ricco@gmail.com