Touches Detection and Other Remaining Parts Lecture 3 1.

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Animation Pre-Lab Lecture 3 1. Revisit 2  Pre-Lab 2  Create new UI components through codes  Too many UI components that are required to put on the.
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
Game Rules Implementation Lecture 5 1. Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and.
Other Input Methods Pre-Lab Lecture 4 1. Revisit 2  Pre-Lab 3 – Animation  Boundary Information  Layer Concept  Animation algorithm  Next Position.
UIAlertView, UIActionSheet, and Facebook Connection Lecture 4 1.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
The Science of Digital Media Microsoft Surface 7May Metropolia University of Applied Sciences Display Technologies Seminar.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Sketchify Tutorial Graphics and Animation in Sketchify sketchify.sf.net Željko Obrenović
Games and Simulations O-O Programming in Java The Walker School
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 4 Reports, Forms, and Combo Boxes.
EEC-492/592 Kinect Application Development Lecture 10 Wenbing Zhao
Introduction to TouchDevelop
GAME:IT Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Chapter 2 Creating a Research Paper with References and Sources Microsoft Word 2013.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Four Fundamental Pieces Instruction Control Structure Function Expression.
1. Chapter 10 Managing and Printing Documents 3 Working with Files and Printing You can open multiple documents in Word. When multiple documents are.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Neo-Breakout Sonhui Schweitzer CS 470 Spring 2005.
VISTA IMAGING RADIOLOGY VIEWER. 2 The focus of this document is on the VistA Imaging Display Radiology Viewer. Other Display changes will be discussed.
Game Maker Terminology
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software
Sound Effects The library Cocosdenshion subproject of cocos2d-iphone targeted at game audio needs Sound effects can be loaded at application startup, so.
Computer Science I Looping. User input. Classwork/Homework: Incorporate looping & user input into a sketch.
G RAPHICS & I NTERACTIVE P ROGRAMMING Lecture 2 More Programming with Processing.
Unit 6 Motion – Air Hockey Evangel College S.2 ICT.
Pemrograman Berbasis Web
1 CSC103: Introduction to Computer and Programming Lecture No 16.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Tablets: Tablet touchscreens Suitable for: Beginner.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
4.5. Respond to the touch interface 4.6. Code additional HTML5 APIs 4.7. Access device and operating system resources JavaScript Coding for the Touch Interface,
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
CHAPTER 7 TouchGestures. Chapter objectives: To code the detection of and response to touch gestures. Patterns of common touches to create touch gestures.
App Inventor Chapter 17 – Creating Animated Apps.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Touch and Go: Leading Touch UI with Open Source
Workshop 3.1 Sketching DesignModeler.
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
DATA HANDLING.
Google Photos: How to Create Animations
More programming with "Processing"
EEC-492/693/793 iPhone Application Development
Game Programming Algorithms and Techniques
CSC 221: Introduction to Programming Fall 2018
Presentation transcript:

Touches Detection and Other Remaining Parts Lecture 3 1

Organization 2  Part 2 – Touches Detection  2.1 Touches Events and Simple Touch Actions  2.2 Dragging the manImage  Part 3 – Remaining Parts  3.1 Collision Detection  3.2 Update Information  3.3 Game End Condition

Touches Actions and Gestures 3  Touches Actions and Gestures  Tapping  Single Tap – touch a single point of the screen once  Double Tap – touch a single point of the screen twice  Multitouch  Touch several points on the screen simultaneously  Dragging  Touch on a certain UI component and move the center of the UI component  Swipping  Move on the screen to the right or left to represent next/prev page  Zooming In or Out  Move two fingers towards or outwards to represent zoom out or zoom in gesture

Tapping – Single Tap 4 Screen View Touch point on screen Touch a Single Point on the Screen

Tapping – Double Taps and Multiple Taps 5 Screen View First touch point on screen Second touch point on screen Double Taps: Touch a single point on the screen twice within a short period of time Multiple Taps: Tap more than twice are possible to be detected

MultiTouches 6 Screen View Touch point 1 MultiTouches: It is possible to detect more than one touch on the screen simultaneously Touch point 2

Dragging 7 Screen View Dragging: Touch on a certain UI component (cannot apply action type) and move to other place on the screen together with the UI component

Swipping 8 Screen View Swipping: Touch on a certain point on the screen and move to other place Usually, moving right is used to represent the gesture of next page, and moving left is used to represent the gesture of previous page

Zooming In/Out 9 Screen View Zooming out: Two fingers touch on the screen simultaneously and move towards each other. This is to represent the gesture that we would like to zoom out to look less detail on the image Zooming in: Two fingers touch on the screen simultaneously and move outwards

Basic Touches Event Handlers 10  Traditionally, iPhone SDK does not provide any method for interpreting the touches actions and gestures  They only provide three basic methods for handling three different stages of touches events  Touches Began Event  This method will be invoked ONCE when the finger first touches on the screen every time  Touches Moved Event  This method will be invoked CONTINUOUSLY when the finger moves on the screen  Touches Ended Event  This method will be invoked ONCE when the finger leaves the screen

Basic Touches Method 11  Your iPhone app can handle the three mentioned basic touch events by implementing the following methods inside the view controller.m file, i.e., no need declare the methods in.h file // Touches Began Method -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ Began”); } // Touches Moved Method -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ Moved”); } // Touches Ended Method -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ Ended”); }

Part 2.1 – Simple Touch Actions Test 12  You may wonder the relationship between the touch events and touch actions  We will then discuss how to interpret several common touches actions from these touches events  Single Tap on Screen  Moving on the Screen  Double Taps on the Screen  Two Touches on the Screen

Situation 1 – Single Tap on Screen 13 TouchesBegan TouchesEnded Finger touches the screen Finger leaves the screen

Situation 2 – Moving on the Screen 14 TouchesBegan TouchesEnded Finger touches the screen Finger leaves the screen TouchesMoved Finger moves on the screen

Information Provided by a Touch Event 15  Within each touch event method, you can request to give you some more detailed information  How many touches currently identified on the screen  The touch point of each touch on the screen  How many times a certain point is touch consecutively

Example: Number of touches 16 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // By invoking the allTouches method of event, which is provided as the input parameters of the touches method (i.e., touches began method in this case), a set of touches will be returned. // Note that the return type is NSSet, and it is just a convention of using allTouches as a variable to hold the set. You can definitely use our variable name.  NSSet * allTouches = [event allTouches]; // Number of touches simultaneously on screen // Recall that allTouches is the variable holding the set of touches on the screen. // We can ask for how many touches occur on the screen by asking for its size directly  [allTouches count]; }

Example: Information of the first touch object 17 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{  NSSet * allTouches = [event allTouches];  UITouch * touch = [[allTouches allObjects] objectAtIndex:0]; // Touch Point Location Information // By invoking the locationInView method of the UITouch, we can get the actual touch point location of this touch on our current screen view by using our current screen view as the input parameter, i.e., [self view]  CGPoint touchPoint = [touch locationInView:[self view]]; // Number of Consecutive Touches on a single point // Recall that touch is a variable referring to a specific touch information on the screen // We can invoke its tapCount method to get this information  [touch tapCount]; }

Situation 3 – Double Taps or Multi Taps 18  NSSet * allTouches = [event allTouches];  UITouch * touch = [[allTouches allObjects] objectAtIndex:0];  switch ([touch tapCount]){  case 2:{  a point 2 times on screen”);  CGPoint touchPoint = [touch locationInView:[self view]];  %f, y: %f”, touchPoint.x, touchPoint.y);  } }

 NSSet * allTouches = [event allTouches];  switch([allTouches count]){  case 2:{  2 points on screen”);  UITouch * touch1 = [[allTouches allObjects] objectAtIndex:0];  CGPoint touchPoint1 = [touch1 locationInView:[self view]];  %f, y: %f”, touchPoint1.x, touchPoint1.y);  UITouch * touch2 = [[allTouches allObjects] objectAtIndex:1];  CGPoint touchPoint2 = [touch2 locationInView:[self view]];  %f, y: %f”, touchPoint2.x, touchPoint2.y);  } Situation 4 – Two or More Touches on Screen 19

Simulating two touch points in iPhone Simulator 20  In iPhone simulator, single touch point is used by default.  To simulate two points, you can press the OPTION key when you move the mouse pointer on the screen view

Part 2.2 – Touch Moved and Dragging Practice 21  Objective:  Allow the manImage to be dragged horizontally when the user touches on the image.  Algorithm:  Detect the touch move position on screen  Check whether the touch falls on the image or not  If true  Handle the manImage move situation  Problem:  Why do we implement the function in touchesMoved?  How to distinguish whether your finger falls on the image or not?

Image Touch Detection Technique 22  Recall that to detect the touch location on the screen view  UITouch * touch = [[allTouches allObjects] objectAtIndex:0];  CGPoint touchPT = [touch locationInView:[self view]];  To check whether your finger touch falls on the image  touchPT.x > x1 and touchPT.x < x2  touchPT.y > y1 and touchPT.y <y2  Note that: x2 = x1+width, y2 = y1+height (x1, y1)(x2, y1) (x1, y2) (x2, y2)

manImage Move Situation 23  Nx = New Center Point X coordinate = Touch Point X Coordinate  Ny = New Center Point Y coordinate = Old Center Point Y Coordinate  [manImage setCenter:CGPointMake(Nx, Ny)]; Center Point Touch Point Old Center Point Touch Point New Center Point

Confine manImage to Move Within Boundary I 24 (0, 0) (480, 320) (480, 0) (0, 320) Right Boundary Left Boundary Right Point: (Nx + width / 2, Ny) Left Point: (Nx – width/2, Ny)

Confine manImage to Move Within Boundary II 25  Allow Movement if  Moving within Left Boundary  X coordinate of New Left Point of manImage: (Nx - Width / 2)  X coordinate of New Left Point of manImage > Left Boundary  Moving within Right Boundary  X coordinate of New Right Point of manImage: (Nx + Width / 2)  X coordinate of New Right Point of manImage < Right Boundary  Not Allow Movement Otherwise

Part 3 Missing Parts of the Game 26  Part 3.1 Collision Detection  This is necessary to detect whether various animating images collide with each other  Part 3.2 Game Information Update  Determine scores and allow the game to progress  Part 3.3 Game End Condition  This is necessary to determine when the game should end  Part 3.4 Reset Game States  Part 3.5 Game Cheat (Challenge of today)

Common Collision Technique I 27  Each image object is treated as a circle with a radius on the screen  The radius can be approximated by width/2 or height/2  If the sum of the radius of two objects is less than the distance between their center positions  Then, the two objects are considered to be collided.  To simplify your work, you can add the following method to the view controller to check whether two objects collide  -(bool) collide : (float) x1 : (float) y1 : (float) r1 : (float) x2 : (float) y2 : (float) r2 { float centerDistance = sqrt(pow((x1-x2),2) + pow((y1-y2),2)); return (centerDistance < (r1 + r2)); }

Collision Detection Technique II 28 Radius of volcanoRock Distance between manImage and volcanoRock Radius of manImage Not Colliding Colliding

manImage and volcanoRock Collision Detection Algorithm 29  For each volcanoRock, check whether it collides with manImage  If yes,  Remove the volcanoRock from superview  Remove the volcanoRock from volcanoRockArray

Game Cheat - Challenge of Today 30  Touch the VolcanoRock will make it vanish  Hints:  Consider the touch event used  Think about how to detect the volcano rock object is touched