tutorials.de Buch-Aktion 05/2012
Seite 2 von 2 ErsteErste 12
ERLEDIGT
JA
ANTWORTEN
17
ZUGRIFFE
2630
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #16
    3dsmaxer 3dsmaxer ist offline Mitglied Gold
    Registriert seit
    Jan 2002
    Ort
    hinterm mond
    Beiträge
    159
    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.
     

  2. #17
    Hiiims Hiiims ist offline Mitglied
    Registriert seit
    Jun 2007
    Beiträge
    24
    Zitat Zitat von 3dsmaxer Beitrag anzeigen
    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):
    PHP-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.0f250.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.+= 0.5f ballbeschl ballgeschw.t;
                
    ballgeschw.+= 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.MaxX)
                {
                    
    ballgeschw.*= -1;
                    
    ballposition.MaxX;
                }

                else if (
    ballposition.MinX)
                {
                    
    ballgeschw.*= -1;
                    
    ballposition.MinX;
                }

                if (
    ballposition.MaxY)
                {
                    
    ballgeschw.*= -1;
                    
    ballposition.MaxY;
                }

                else if (
    ballposition.MinY)
                {
                    
    ballgeschw.*= -1;
                    
    ballposition.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(ballballpositionColor.White);
                
    spriteBatch.End();
                
    base.Draw(gameTime);
            }
        }

    Damit muss es tun, bei mir geht's doch auch. Sonst machst du was mutwillig falsch

    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)
     

  3. #18
    3dsmaxer 3dsmaxer ist offline Mitglied Gold
    Registriert seit
    Jan 2002
    Ort
    hinterm mond
    Beiträge
    159
    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

  1. Bewegung...
    Von Mailyn im Forum Visual Basic 6.0
    Antworten: 2
    Letzter Beitrag: 05.09.05, 22:46
  2. beschleunigte bewegung an schiefer linie
    Von Lloyd im Forum Flash Plattform
    Antworten: 2
    Letzter Beitrag: 10.08.05, 18:47
  3. Bewegung...
    Von Mailyn im Forum Visual Basic 6.0
    Antworten: 12
    Letzter Beitrag: 14.07.05, 15:19
  4. HELP bewegung programmieren!
    Von mama-karl im Forum Flash Plattform
    Antworten: 2
    Letzter Beitrag: 21.04.05, 10:49
  5. [mx] stop bewegung
    Von Rip van Winkle im Forum Flash Plattform
    Antworten: 7
    Letzter Beitrag: 04.11.02, 09:36