Nothing Special   »   [go: up one dir, main page]

ZEN X-Fi2 ADK Programmer's Guide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Application Development Kit

Programmer's Guide
Version 1.02

COPYRIGHT
Copyright 2010 Creative Technology Ltd. All rights reserved. The material in this document is the intellectual property of Creative and is provided solely for information. You may not reproduce this document in whole or in part by any means. While every care has been taken in the preparation of this document, Creative accepts no liability for any consequences of its use. Our products are under continual improvement and we reserve the right to change their specification without notice. License for Lua 5.0 and later versions Copyright 19942008 Lua.org, PUC-Rio. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Libpng version 1.2.40-September 10, 2009 Copyright 1998-2009 Glenn Randers-Pehrson. Copyright 1996-1997 Andreas Dilger. Copyright 1995-1996 Guy Eric Schalnat, Group 42, Inc.

Copyright 2010 Creative Technology Ltd. All rights reserved.

Table of Contents

Introducing ZEN X-Fi2 Application Development Kit . . . . . . . . . . . . . . . . . . 4 About the ZEN X-Fi2 Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating Your First Application ................................ 5 6 9

About the API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Copyright 2010 Creative Technology Ltd. All rights reserved.

Introducing ZEN X-Fi2 Application Development Kit


With the use of firmware version 1.10.04 or later, your ZEN X-Fi2 can support Lua-based games and applications that were developed using the ZEN X-Fi2 Application Development Kit (ADK). Using this development kit, you can easily develop your own games and applications on your Windows-based computer, and then install them in your ZEN X-Fi2 player. The ZEN X-Fi2 ADK comes with the following: 1. ZEN X-Fi2 Simulator This application enables you to write and debug games and applications on your computer with the use of the Lua programming language. 2. Programmers Guide This document introduces the ADK and guides you in developing your own games or applications for ZEN X-Fi2. To instantly access the Programmers Guide, click Help on the ZEN X-Fi2 Simulators menu. 3. API Reference API stands for Application Programming Interface. The API Reference document that comes with the ADK contains the predefined functions that you can use when your write your applications. To instantly access the API Reference, click Help on the ZEN X-Fi2 Simulators menu. What is Lua? Lua is currently the leading scripting language in games and is a powerful, fast, lightweight, embeddable scripting language that combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.* *This text is extracted from the Lua web site at http://www.lua.org/about.html.

Copyright 2010 Creative Technology Ltd. All rights reserved.

About the ZEN X-Fi2 Simulator


When you run the ZEN X-Fi2 Simulator, you can see two windows: Creative ZEN X-Fi2 window This window simulates your ZEN XFi2's touchscreen. You can test your new application on this window. The default application list contains API demos for Sound, GUI, and Control libraries. Note that applications that use audio and accelerometer functions can only be tested on the ZEN X-Fi2 player itself. Log window This window shows the debug information.

You can instantly access this Programmer's Guide and the API Reference at any time from the Help menu.

Copyright 2010 Creative Technology Ltd. All rights reserved.

Creating Your First Application


Your applications would require an icon file (icon.png or icon.bmp) and a script file (main.lua). This files should be inside a folder named similarly to the application. The recommended resolution for the icon file is 50 x 70 pixels or less. The procedure below shows you how to make a simple application called "Hello ZEN". 1. Create a folder Hello ZEN under the directory C:\Creative\ZEN XFi2\Applications. 2. Create the icon.png or icon.bmp file and save it inside the Hello ZEN folder. 3. In the same folder, create the main.lua file containing the following codes: --this is my first Lua application height = screen.height() width= screen.width() black = color.new(0,0,0) red = color.new(255,0,0) screen.fillrect(0,0,width,height,black) oldsize=text.size(30) oldcolor=text.color(red) string = "Hello ZEN!" text.draw(0,80,string,"center",width) screen.update() text.size(oldsize) text.color(oldcolor) screen.update() while 1 do if control.read()==1 then if control.isTouch()==1 then screen.fillrect(0,0,width,height,black) oldsize=text.size(30) oldcolor=text.color(red) x,y = touch.pos() string = "Hello ZEN!" text.draw(x+20,y,string,"left",width) screen.update() text.size(oldsize) text.color(oldcolor) elseif control.isButton()==1 then if button.click()==1 then break end end else os.sleep(10) end end 4. Run ZEN X-Fi2 Simulator again. The Hello ZEN application is then added in the Application list.

Copyright 2010 Creative Technology Ltd. All rights reserved.

When you click the program icon, the result will look like the sample snapshot below. When you click and drag the mouse on the screen, the "Hello ZEN!" string will follow.

5. Debug in ZEN X-Fi2 Simulator. You can use print() function in Lua script to print the value of the variable in the log window. For example: number = 0 string = DEBUG-the number value is:..number print(string) The string will appear in the Log window.

Copyright 2010 Creative Technology Ltd. All rights reserved.

6. Connect your ZEN X-Fi2 player to the PC via USB cable. 7. Copy the Hello ZEN folder into the Applications folder of your ZEN X-Fi2 player. The Hello ZEN application is now added to the Application list in the player.

Copyright 2010 Creative Technology Ltd. All rights reserved.

About the API Reference


The ZEN X-Fi2 API Reference document includes the following libraries: Library GUI library Control library System library Description Provides methods for certain screen functions, such as rotate screen, draw line, draw image, and others. Captures action inputs, such as button press, taps/touches, accelerometer input. os.getenv() and os.wait() are re-implemented in ZEN X-Fi2 ADK.

Sound library Provides methods for audio functions, such as playing WAV files, adjusting the volume, changing channels, and others. Refer to the API Reference document for details.

Copyright 2010 Creative Technology Ltd. All rights reserved.

You might also like