ERLEDIGT
JA
JA
ANTWORTEN
17
17
ZUGRIFFE
2630
2630
EMPFEHLEN
-
ich habe gemacht, was du gesagt hast.
genau diese 3 zeilen hatte ich ja am anfang auch....
es ist wieder da selbe problem. der ball bewegt sich extrem langsam und mit konstanter geschwindigkeit.
wenn t sich nicht ändert, heißt das die zeit ist konstant (was auf der erde nicht vorkommt) und das würde auch bedeuten, dass die beschleunigung nicht vorhanden ist, da beschleunigung heißt, dass sich die geschwindigkeit mit der zeit ändert.
c# oder visual studio oder XNA bekommts anscheinend nicht gebacken. bzw. ich weiß nicht wie es sonst gehen soll.
ich gebe auf.
-
falsche Einstellung.
wenn du es mit diesem Quellcode versucht funkioniert es auf jedenfall (es ist deiner, ich hab ihn nur an einigen Stellen einwenig (nicht komplett) dem Standard angepasst):
Damit muss es tun, bei mir geht's doch auch. Sonst machst du was mutwillig falschPHP-Code: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);
}
}
}

t muss sich nicht ändern um einige Geschwindigkeitsänderung zu erreichen, denn t ist ja lediglich die Zeit vom letzten Update()-Aufruf bis zum jetztigen und du berechnest ja nur, in wie fern sich der Ball innerhalb der letzen Zeitabstandes beschleunigt hat und addierst diese zu eigentlichen Geschwindigkeit hinzu (->beschleunigt). Was du anscheinend von t erwartest, ist, dass es von dem Start des Spiels bis zum jetztigen Update()-Aufruf die Zeit angibt. Das musst dann erst selber in einer Variable mitspeichern, denn, wie gesagt, gibt "gameTime.ElapsedGameTime.TotalSeconds;" die Zeit von letzten Update bis zum Jetzigen in Sekunden an.Geändert von Hiiims (26.04.08 um 00:20 Uhr)
-
tausend Dank.
Mit deinem Quellcode klappts.
Ich werde nun auf die Fehlersuche gehen, vielleicht verstehe ich es ja und habe noch Spaß mit XNA und c#.
Ähnliche Themen
-
Bewegung...
Von Mailyn im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 05.09.05, 22:46 -
beschleunigte bewegung an schiefer linie
Von Lloyd im Forum Flash PlattformAntworten: 2Letzter Beitrag: 10.08.05, 18:47 -
Bewegung...
Von Mailyn im Forum Visual Basic 6.0Antworten: 12Letzter Beitrag: 14.07.05, 15:19 -
HELP bewegung programmieren!
Von mama-karl im Forum Flash PlattformAntworten: 2Letzter Beitrag: 21.04.05, 10:49 -
[mx] stop bewegung
Von Rip van Winkle im Forum Flash PlattformAntworten: 7Letzter Beitrag: 04.11.02, 09:36





Zitieren
Login





