TouchDevelop Chapter 8-10 Presenter: Jing Xu 1 Outline 2 Interactions Game Board Tiles and Printing Interactions 3 SMS messages Social messages Calendar and appointments Contacts Locations, places, maps Emails Phone Calls 2D barcodes SMS messages 4 SMS is an abbreviation for Short Message Service. The TouchDevelop API allows a script to generate an SMS message ready for transmission but it will not actually send it. Demo: SMS(phone) Social messages 5 Several websites, including Twitter and Facebook in particular, provide the ability to post messages for other people to read. The TouchDevelop API provides facilities for downloading such messages and for posting new messages. Demo: SocialMessage Calendar and appointments 6 The Windows phone provides a calendar where each day’s schedule, comprised of various meetings or appointments, is recorded. A TouchDevelop script has read-only access to the phone’s calendar and can retrieve all the appointments for a specific range of times. Demo: Calendar(phone) Contacts 7 Each contact contains several fields. All fields except for the name are optional. We can use the API to access and change the list of contacts. When some part of the contact’s information has been changed, the updated contact may be saved back to the phone’s contact list by using the social→save contact method. Locations&Maps 8 A location can be created or described by using the methods of the locations resource. Locations&Maps(Cont.) In addition to the methods provided by the locations service, location values can be obtained from several other sources. Here is a list of the possibilities. – – – – – – – – 9 senses → current location senses → current location accurate maps → directions location method of the Link datatype center method of the Map datatype location method of the Message datatype location method of the Picture datatype location method of the Place datatype Demo: Locations(phone) Emails 10 A TouchDevelop script can prepare an email message ready for transmission, but it does not actually send it. Demo: Email(phone) Phone Calls 11 A script can prepare for a phone call by setting up the number and transferring control to the phone’s software for making the call. Demo: Phone(phone) 2D barcodes 12 TouchDevelop provides access to the Microsoft Tag service which generates twodimensional barcodes for text messages and for URLs. 13 Game Board 14 Introduction Board Datatype Sprite Datatype Sprite Collection Datatype Touching and board event Debugging game Sprite 15 Sprites are 2D bitmaps that are drawn directly to the screen. Sprites are commonly used to display information such as health bars, number of lives, or text such as scores. TouchDevelop allows creation and use of several types of sprite, such as ellipse, rectangle, text and picture. Game program structure 16 The game loop event is triggered approximately every 50 milliseconds The Board datatype 17 Methods of Board datatype: appearance 18 Sprite 19 Sprites are associated with particular game boards and are created by methods of the Board type Methods of Board datatype: creating / accessing sprites 20 Obstacles and boundaries 21 Obstacles are walls that can be added to the board Walls cannot be moved once created. Moving sprites which encounter an obstacle will bounce back with a speed determined by the product of the obstacle’s elasticity and the sprite’s elasticity. Methods of Board datatype: obstacles / boundaries 22 Forces and animation 23 A uniform force can be applied to all sprites on the board. The force need not remain constant. Methods of Board datatype: forces / animation 24 Demo 25 MovingBall(phone) Springs 26 A spring can be added between two sprites to make them accelerate towards each other. The force of the spring is proportional to the distance between the two sprites. The further they are apart, the stronger the force. Demo: CreateSpring Anchors 27 One way to produce an unmovable sprite is to set its friction to 1. An alternative possibility is to use an invisible anchor sprite. The create anchor method creates the invisible sprite with its friction set to 1.0. The Sprite datatype 28 Sprites are movable objects which visually represent parts of a game. Position and motion 29 A sprite has a current position and a current angular orientation. Both of these change at rates determined by the sprite’s speed and its angular velocity. Methods of Sprite datatype: mass, friction, elasticity 30 Demo: CreateSprite The Sprite Collection datatype 31 When writing simple games with multiple objects of the same kind (e.g. multiple shots, missiles, etc.), it quickly becomes necessary to group related sprites into collections. A Sprite Set is an ordered set. A value can appear at most once in the set. The elements of the set are ordered by their index positions. Touching and board events 32 These events are triggered when the user touches the screen and taps, swipes or drags a finger across the board. tap board event 33 The tap board event fires if there is tap anywhere on the board except on a position where a sprite is located. The tap board event has two parameters x and y which give the position where the tap occurred. Demo: TapBoard swipe board event 34 The swipe board event is similar, except that the event code is passed four parameters. The first two show where the swipe started and the second two show the extent of the swipe in the x and y dimensions. Demo: SwipeBoard tap sprite in XXX event 35 Tap events can be provided for sprites held in different sprite collections. Demo: TapinXXX swipe sprite in XXX event 36 The swipe sprite event is similar to the tap sprite event, except that one’s finger is swiped across the screen and the extent of the swipe is passed as two additional parameters. drag sprite in XXX event 37 A drag event does not wait for the finger to be lifted from the screen, as with the tap and swipe events. It fires while one’s finger is still on the screen. It will repeatedly fire while the finger is in motion across the screen. Demo: TapinXXX tap sprite SSS, swipe sprite SSS, drag sprite SSS 38 We can also have events associated with an individual sprite. The sprite must be promoted to be a global data variable Debugging games 39 If debug mode is on, the board will display the position and speed of a sprite next to the sprite content. Additionally, the width and height is displayed as a box around the sprite. Also, in debug mode, even invisible sprites are displayed. Demo: SwipeBoard Tiles 40 Pinning the tile simply means creating a tile on the home screen Tiles always have a front side; they optionally can have a back side. When there is both a front side and a back side, the phone’s software randomly flips the tile over to show the other side. Tiles 41 A tile can be associated with an action in a TouchDevelop script. If the script contains more than one publicly visible action, there can be more than one tile for the script. General steps 42 Create the action which is to be invoked when the tile is tapped. The action need not contain any code at this point. Run the action to its conclusion. When the action has finished, a row of icons appears across the bottom of the phone’s screen. One of the icons is a pushpin. This icon should be tapped. Programming the tile’s content 43 A new global data item. It has the name XXX tile. Demo-SMS(phone) Printing via a home server 44 A home network may include one or more printers. These printers would normally be attached to the network via their WiFi capabilities. Two API for connecting to a printer 45 The TouchDevelop script provides two API methods for connecting to a printer. References [1] 46 https://www.touchdevelop.com/book Questions? 47 Thank you! 48
© Copyright 2026 Paperzz