|
Fraseer و Xna
|
|
نويسنده |
پيغام |
L u K e کاربر جدید
تاريخ عضويت: جمعه 12 مهر 1387 تعداد ارسالها: 17
3 شنبه 19 خرداد 1388 - 11:26 |
|
|
ُسلام
اقا من یه مشکل دارم با fraseer ( موتور فیزیک )
من وقتی از Dll ش استفاده می کنم مورد می گیره چرا ؟
مگه نباید خودش اتوماتیک برخورد و این چیزا رو حساب کنه ؟
پس واسه چی هیچ کاری نمی کنه
اگه کسی اموزش فارسی داره بزاره
اینم Sorce برنامم
وقتی Ball به Platform( زمین ) برخورد می کنه هیچ اتفاقی نمی افته ؟
platform یه جسم ساکنه
كد: |
using System;
using System.Collections.Generic;
using System.Linq;
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.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Controllers;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Factories;
using FarseerGames.FarseerPhysics.Interfaces;
using FarseerGames.FarseerPhysics.Mathematics;
using FarseerGames.FarseerPhysics;
namespace Farseer
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
PhysicsSimulator World;
Body BBall;
Body BPlatform;
Geom GBall;
Geom GPlatform;
Texture2D Platform;
Texture2D Ball;
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();
World = new PhysicsSimulator(new FarseerGames.FarseerPhysics.Mathematics.Vector2(0, 10));
BBall = BodyFactory.Instance.CreateRectangleBody(World,100, 30, 10);
BBall.position.X = 300;
GBall = GeomFactory.Instance.CreateRectangleGeom(BBall, 300, 100);
BPlatform = BodyFactory.Instance.CreateRectangleBody(800, 100, 1000);
GPlatform = GeomFactory.Instance.CreateRectangleGeom(BPlatform, 800, 100);
BPlatform.position = new FarseerGames.FarseerPhysics.Mathematics.Vector2(0, 500);
BPlatform.IsStatic = true;
World.Add(BBall);
World.Add(BPlatform);
}
/// <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);
Ball = Content.Load<Texture2D>("Box");
Platform = Content.Load<Texture2D>("G");
// 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();
World.Update(1f);
base.Update(gameTime);
}
/// <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)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(Platform, new Microsoft.Xna.Framework.Vector2(BPlatform.position.X, BPlatform.Position.Y), Color.White);
spriteBatch.Draw(Ball, new Microsoft.Xna.Framework.Vector2(BBall.position.X,BBall.position.Y), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
|
|
|
|
بازگشت به بالا |
|
|
|
|
|
|
|
نويسنده |
پيغام |
مهدي بازيان مدیر انجمن
تاريخ عضويت: 1 شنبه 5 تير 1384 تعداد ارسالها: 430 محل سكونت: اصفهان
5 شنبه 21 خرداد 1388 - 22:16 |
|
|
چند تا ایراد داشت که بدون ایرادش را این زیر گذاشتم :
( اکثر ایرادها مربوط میشد به ندوستن مفهوم Body و Geom و تفاوتشون )
كد: |
using System;
using System.Collections.Generic;
using System.Linq;
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.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using FarseerGames.FarseerPhysics.Collisions;
using FarseerGames.FarseerPhysics.Controllers;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Factories;
using FarseerGames.FarseerPhysics.Interfaces;
using FarseerGames.FarseerPhysics.Mathematics;
using FarseerGames.FarseerPhysics;
namespace Farseer
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
PhysicsSimulator World;
Body BBall;
Body BPlatform;
Geom GBall;
Geom GPlatform;
Texture2D Platform;
Texture2D Ball;
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();
World = new PhysicsSimulator(new FarseerGames.FarseerPhysics.Mathematics.Vector2(0, 0));
BBall = BodyFactory.Instance.CreateRectangleBody(World, 100, 30, 10);
BBall.position.X = 300;
GBall = GeomFactory.Instance.CreateRectangleGeom(World,BBall, 100, 30);
BPlatform = BodyFactory.Instance.CreateRectangleBody(World, 800, 100, 1000);
BPlatform.position = new FarseerGames.FarseerPhysics.Mathematics.Vector2(400, 500);
GPlatform = GeomFactory.Instance.CreateRectangleGeom(World,BPlatform, 800, 100);
BPlatform.IsStatic = true;
World.Gravity = new FarseerGames.FarseerPhysics.Mathematics.Vector2(0, 100);
GPlatform.RestitutionCoefficient = 1f;
GPlatform.FrictionCoefficient = .4f;
}
/// <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);
Ball = Content.Load<Texture2D>("Box");
Platform = Content.Load<Texture2D>("Ground");
// 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();
World.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
base.Update(gameTime);
}
/// <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)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(Platform, new Microsoft.Xna.Framework.Vector2(BPlatform.Position.X - (Platform.Width / 2f), BPlatform.Position.Y - (Platform.Height / 2f)), Color.White);
spriteBatch.Draw(Ball, new Microsoft.Xna.Framework.Vector2(GBall.Position.X - (Ball.Width / 2f), GBall.Position.Y - (Ball.Height / 2f)), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
|
|
|
|
بازگشت به بالا |
|
|
|
|
|
صفحه 1 از 1 |
تمام ساعات و تاريخها بر حسب 3.5+ ساعت گرينويچ مي باشد
|
|
شما نمي توانيد در اين انجمن نامه ارسال كنيد. شما نمي توانيد به موضوعات اين انجمن پاسخ دهيد شما نمي توانيد نامه هاي ارسالي خود را در اين انجمن ويرايش كنيد شما نمي توانيد نامه هاي ارسالي خود را در اين انجمن حذف كنيد شما نمي توانيد در نظر سنجي هاي اين انجمن شركت كنيد
|
|
|