Download presentation
Presentation is loading. Please wait.
Published byElfrieda Pearson Modified over 9 years ago
1
1 TouchDevelop Chapter 8-10 Presenter: Jing Xu
2
2 Outline Interactions Game Board Tiles and Printing
3
3 Interactions SMS messages Social messages Calendar and appointments Contacts Locations, places, maps Emails Phone Calls 2D barcodes
4
4 SMS messages 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)
5
5 Social messages 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
6
6 Calendar and appointments 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)
7
7 Contacts 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.
8
8 Locations&Maps A location can be created or described by using the methods of the locations resource.
9
9 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. – 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)
10
10 Emails A TouchDevelop script can prepare an email message ready for transmission, but it does not actually send it. Demo: Email(phone)
11
11 Phone Calls 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)
12
12 2D barcodes TouchDevelop provides access to the Microsoft Tag service which generates two- dimensional barcodes for text messages and for URLs.
13
13
14
14 Game Board Introduction Board Datatype Sprite Datatype Sprite Collection Datatype Touching and board event Debugging game
15
15 Sprite 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.
16
16 Game program structure The game loop event is triggered approximately every 50 milliseconds
17
17 The Board datatype
18
18 Methods of Board datatype: appearance
19
19 Sprite Sprites are associated with particular game boards and are created by methods of the Board type
20
20 Methods of Board datatype: creating / accessing sprites
21
21 Obstacles and boundaries 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.
22
22 Methods of Board datatype: obstacles / boundaries
23
23 Forces and animation A uniform force can be applied to all sprites on the board. The force need not remain constant.
24
24 Methods of Board datatype: forces / animation
25
25 Demo MovingBall(phone)
26
26 Springs 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
27
27 Anchors 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.
28
28 The Sprite datatype Sprites are movable objects which visually represent parts of a game.
29
29 Position and motion 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.
30
30 Methods of Sprite datatype: mass, friction, elasticity Demo: CreateSprite
31
31 The Sprite Collection datatype 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.
32
32 Touching and board events These events are triggered when the user touches the screen and taps, swipes or drags a finger across the board.
33
33 tap board event 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
34
34 swipe board event 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
35
35 tap sprite in XXX event Tap events can be provided for sprites held in different sprite collections. Demo: TapinXXX
36
36 swipe sprite in XXX event 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.
37
37 drag sprite in XXX event 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
38
38 tap sprite SSS, swipe sprite SSS, drag sprite SSS We can also have events associated with an individual sprite. The sprite must be promoted to be a global data variable
39
39 Debugging games 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
40
40 Tiles 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.
41
41 Tiles 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.
42
42 General steps 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.
43
43 Programming the tile’s content A new global data item. It has the name XXX tile. Demo-SMS(phone)
44
44 Printing via a home server A home network may include one or more printers. These printers would normally be attached to the network via their WiFi capabilities.
45
45 Two API for connecting to a printer The TouchDevelop script provides two API methods for connecting to a printer.
46
46 References [1] https://www.touchdevelop.com/book
47
47 Questions?
48
48 Thank you!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.