Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
float t = (float)gameTime.ElapsedGameTime.TotalSeconds;
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Diagnostics;
namespace WindowsGame2
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D strand;
Texture2D ball;
Vector2 ballposition = Vector2.Zero;
Vector2 ballgeschw = new Vector2(50.0f, 250.0f);
float ballbeschl = 20f;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
strand = Content.Load<Texture2D>("strands");
ball = Content.Load<Texture2D>("ball");
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
UpdateSprite(gameTime);
base.Update(gameTime);
}
void UpdateSprite(GameTime gameTime)
{
//Ball bewegen
float t = (float)gameTime.ElapsedGameTime.TotalSeconds;
Debug.Write(t);
float ballbeschlhalb = 0.5f * ballbeschl;
Debug.Write(ballbeschlhalb);
float ballgeschwmalt = ballgeschw.X * t;
Debug.Write(ballgeschwmalt);
float tquadr = t * t;
Debug.Write(tquadr);
ballposition.X += ballbeschlhalb * tquadr + ballgeschwmalt ;
int MaxX = graphics.GraphicsDevice.Viewport.Width - ball.Width;
int MinX = 0;
int MaxY = graphics.GraphicsDevice.Viewport.Height - ball.Height;
int MinY = 0;
//Kollisionsabfrage
if (ballposition.X > MaxX)
{
ballgeschw.X *= -1;
ballposition.X = MaxX;
}
else if (ballposition.X < MinX)
{
ballgeschw.X *= -1;
ballposition.X = MinX;
}
if (ballposition.Y > MaxY)
{
ballgeschw.Y *= -1;
ballposition.Y = MaxY;
}
else if (ballposition.Y < MinY)
{
ballgeschw.Y *= -1;
ballposition.Y = MinY;
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.White);
// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(strand, Vector2.Zero, Color.White);
spriteBatch.Draw(ball, ballposition, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
float t = (float)gameTime.ElapsedGameTime.TotalSeconds;
ballposition.X += 0.5f * ballbeschl * t * t + ballgeschw.X * t;
ballgeschw.X += ballbeschl * t;
float t = (float)gameTime.ElapsedGameTime.TotalSeconds;
Debug.Write(t);
float ballbeschlhalb = 0.5f * ballbeschl;
Debug.Write(ballbeschlhalb);
float ballgeschwmalt = ballgeschw.X * t;
Debug.Write(ballgeschwmalt);
float tquadr = t * t;
Debug.Write(tquadr);
ballposition.X += ballbeschlhalb * tquadr + ballgeschwmalt ;
falsche Einstellung.ich gebe auf.
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Diagnostics;
namespace WindowsGame2
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public ContentManager content;
Texture2D strand;
Texture2D ball;
Vector2 ballposition = Vector2.Zero;
Vector2 ballgeschw = new Vector2(50.0f, 250.0f);
float ballbeschl = 200f;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
content = new ContentManager(Services);
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent)
{
// Create a new SpriteBatch, which can be used to draw textures.
ball = content.Load<Texture2D>("Content\\ball");
spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
}
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadGraphicsContent(bool unloadAllContent)
{
if (unloadAllContent)
{
// TODO: Unload any ResourceManagementMode.Automatic content
//content.Unload();
}
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
UpdateSprite(gameTime);
base.Update(gameTime);
}
void UpdateSprite(GameTime gameTime)
{
//Ball bewegen
float t = (float)gameTime.ElapsedGameTime.TotalSeconds;
ballposition.X += 0.5f * ballbeschl * t * t + ballgeschw.X * t;
ballgeschw.X += ballbeschl * t;
int MaxX = graphics.GraphicsDevice.Viewport.Width - ball.Width;
int MinX = 0;
int MaxY = graphics.GraphicsDevice.Viewport.Height - ball.Height;
int MinY = 0;
//Kollisionsabfrage
if (ballposition.X > MaxX)
{
ballgeschw.X *= -1;
ballposition.X = MaxX;
}
else if (ballposition.X < MinX)
{
ballgeschw.X *= -1;
ballposition.X = MinX;
}
if (ballposition.Y > MaxY)
{
ballgeschw.Y *= -1;
ballposition.Y = MaxY;
}
else if (ballposition.Y < MinY)
{
ballgeschw.Y *= -1;
ballposition.Y = MinY;
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.White);
// TODO: Add your drawing code here
spriteBatch.Begin();
spriteBatch.Draw(ball, ballposition, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}