Sie sind auf Seite 1von 18

Dimitris Gkanatsios

Academic Developer Evangelist, Microsoft Greece


v-digkan@microsoft.com twitter.com/dgkanatsios

TouchCollection touchCollection = TouchPanel.GetState();


if (touchCollection.Count > 0)
{
TouchLocation touchLocation = touchCollection[0];
if (touchLocation.State ==
TouchLocationState.Released)
{
return;
}
Note: First touch will yield TouchLocationState.Pressed, but
next touches (even in the same Point!) will yield
TouchLocationState.Moved

GestureType

Description

Tap

A finger touches the screen and releases without much


movement.
Two taps in succession.

DoubleTap
Hold
FreeDrag
VerticalDrag
HorizontalDrag
DragComplete

A finger touches the screen and holds it in place for a brief


period of time.
A finger touches the screen and moves in any direction.
A finger touches the screen and moves in an up/down
direction.
A finger touches the screen and moves in a left/right direction.

Pinch

Marks the end of a FreeDrag, VerticalDrag, or HorizontalDrag


gesture.
A finger drags across the screen and is lifted up without
stopping.
Two fingers press on the screen and move around.

PinchComplete

Marks the end of a Pinch gesture.

Flick

Cartesian
X increases to the left
Y increases to the bottom
Use Vector2 to
represent X and Y
Use SpriteBatch.Draw()
to draw

(0,0)

XNA supports jpg, png, bmp


Content pipeline takes care of the importing details for
you

Check the asset name on the properties window


To use it in your project
Load it via Content.Load generic method in a
Texture2D reference

Create a Vector2 structure to hold its location


Update (if needed) its location in the Update method
Draw it via SpriteBatch.Draw method in the Draw method
(do not forget Begin and End methods!)

XNA supports transparency in PNG files

Texture
Position
SourceRectangle
Color
Rotation
Origin
Scale
Effects
LayerDepth

Animation basically
happens inside the
Update method
Move the Vector as
updated by player or AI
Spritesheets are useful for
faster game loading and
animations

Pay attention to it because it often angers


the player!
Use Rectangle.Intersects where possible
If strange shape, try to approximate it
using circles or rectangles

Text drawing
SpriteFont

Game State Management


Custom enumerations

Game Components
GameComponent and
DrawableGameComponent

Sounds
Accessing the GameTime

Found on www.studentguru.gr/blogs/dt008
Open source
With instructions
Updated for RTM
Easily improved
If you upload them to Marketplace and
become a millionaire, please dont forget me

Coordinates - one more


Drawing 2D is like painting a picture on a
canvas
Drawing 3D is like recording a video with a
handheld camera
Depending on camera's location and
direction, an object located at the origin
could appear anywhere on the screen (or
out of it)

X axis moves to the right


Y axis moves up
Z axis moves positively toward you! (right
handed)

You have to define various properties of a camera


View and Projection
info stored in matrices
View matrix holds info about
where the camera sits in the world
what direction it's pointing in
what is its orientation
Projection matrix holds info about
angle of view
how far the camera can see
Projection matrix represents the transformation from the 3D world to the 2D plane of the
screen
Matrix view = Matrix.CreateLookAt(cameraPosition, cametaTarget, cameraUpVector)
Matrix projection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, aspectRatio,
nearPlaneDistance, farPlaneDistance)
projection matrix holds the viewing frustum or field of view
defines an area in 3D space that is viewable by the
camera and will be drawn on the screen

Triangle: root of all 3D drawings


if you draw enough triangles, you can
render almost any shape
How to draw a simple color triangle
DefineVertexPositionColor array
Create a BasicEffect
set its World, View, Projection
enable VertexColor

Draw for each pass of the effect

XNA 3D draws using HLSL


HLSL is based on C
Allows developers to create incredibly
powerful effects
We use HLSL via Effect
XNA 4 provides 5 pre-written effects for the
Phone
You can't write your own, just yet!

http://developer.windowsphone.com
http://www.studentguru.gr/blogs/dt008
www.twitter.com/dgkanatsios
http://creators.xna.com
www.facultyresourcecenter.com
www.dreamspark.com

Das könnte Ihnen auch gefallen