Fórum Sharpgames
 
 
  Forum  Criação de Jogo...  Gráficos 2D/3D  tutorial mappy e xna do luciano
Anterior Anterior
 
Próximo Próximo
Nova Entrada 29/11/2008 12:03
  lucianoJose
195 tópicos
Iniciante


Re: tutorial mappy e xna do luciano  
Modificado Por lucianoJose  em 29/11/2008 10:10:11)
 linuxboy escreveu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
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 LoaderMapFromMappy;
namespace arkanoidxna
{
    /// 
    /// This is the main type for your game
    /// 
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        
        clsSprite myBase; // sprite para a basse
        clsSprite myBall; // sprite para a bolinha
        clsSprite[] myBackground = new clsSprite[10]; //sprite para a imagem de fundo ou telas
        private MappyLoader mappyLoader;
        private MapLayer mapLayer;
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
        /// 
        /// 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.
        /// 
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            this.mappyLoader = new MappyLoader();
            this.mapLayer = new MapLayer(this);
            base.Initialize();
        }
        /// 
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// 
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            
            myBase = new clsSprite(Content.Load("base-arkanoide"),
            new Vector2(280f, 570f), new Vector2(64f, 64f),
            graphics.PreferredBackBufferWidth,
            graphics.PreferredBackBufferHeight);
            myBall = new clsSprite(Content.Load("bolinha"),
            new Vector2(365f, 540f), new Vector2(64f, 64f),
            graphics.PreferredBackBufferWidth,
            graphics.PreferredBackBufferHeight);
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.ApplyChanges();
            
            this.mapLayer.LoadContent("mapa1.FMP", this.mappyLoader);
            this.mapLayer.TileStripTexture = this.Content.Load("tilebloco");
            this.mapLayer.BuildSourceRectanglesTileStrip(3, 2, 5);
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }
        /// 
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// 
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
        /// 
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// 
        /// Provides a snapshot of timing values.
        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
            base.Update(gameTime);
        }
        /// 
        /// This is called when the game should draw itself.
        /// 
        /// Provides a snapshot of timing values.
        protected override void Draw(GameTime gameTime)
        {
            // TODO: Add your drawing code here
            this.graphics.GraphicsDevice.Clear(Color.Black);
            this.spriteBatch.Begin();
            this.mapLayer.Draw(gameTime);
            spriteBatch.Draw(myBall.texture, myBall.position, Color.White);
            spriteBatch.Draw(myBase.texture, myBase.position, Color.White);
            this.spriteBatch.End();
            base.Draw(gameTime);
        }
    }
    class clsSprite
    {
        public Texture2D texture; // plano de fundo
        public Vector2 position; // posição do desenho
        public Vector2 size; // tamanho do desenho em pixels
        public Vector2 screenSize; // tamanho da tela
        public Vector2 velocity; // velocidade do movimento
        // controle de velocidade do objeto
        public void Move()
        {
            // if we'll move out of the screen, invert velocity
            // checking right boundary
            if (position.X + size.X + velocity.X > screenSize.X)
                velocity.X = -velocity.X;
            // checking bottom boundary
            if (position.Y + size.Y + velocity.Y > screenSize.Y)
                velocity.Y = -velocity.Y;
            // checking left boundary
            if (position.X + velocity.X < 0)
                velocity.X = -velocity.X;
            // checking bottom boundary
            if (position.Y + velocity.Y < 0)
                velocity.Y = -velocity.Y;
            // since we adjusted the velocity, just add it to the current position
            position += velocity;
        }
        public clsSprite(Texture2D newTexture, Vector2 newPosition, Vector2 newSize, int ScreenWidth, int ScreenHeight)
        {
            texture = newTexture;
            position = newPosition;
            size = newSize;
            screenSize = new Vector2(ScreenWidth, ScreenHeight);
        }
    }
}



Error 1 The type or namespace name 'LoaderMapFromMappy' could not be found (are you
missing a using directive or an assembly reference?)
D:\Programação\XNA-C#\arkanoidxna\arkanoidxna\Game1.cs 16 7 arkanoidxna
Error 2 The type or namespace name 'MappyLoader' could not be found (are you
missing a using directive or an assembly reference?)
D:\Programação\XNA-C#\arkanoidxna\arkanoidxna\Game1.cs 34 17 arkanoidxna
Error 3 The type or namespace name 'MapLayer' could not be found (are you
missing a using directive or an assembly reference?)
D:\Programação\XNA-C#\arkanoidxna\arkanoidxna\Game1.cs 35 17 arkanoidxna


 


No projeto do programa principal, tem uma pasta chamada "References". Clica com o botão com o direito em cima dela dai você escolhe a opção "Add Reference..."

Vai aparecer uma janela dai você vai na aba "Projects" e deve aparecer o Projeto com nome "LoaderMapFromMappy". Escolhe ele e tenta compilar.

Tenta fazer isso e nos diz algo. vlw!


@lucianoJoseBr My Blog: http://lucjose.wordpress.com
 
Nova Entrada 29/11/2008 12:41
  linuxboy
20 tópicos
9th Level Poster


Re: tutorial mappy e xna do luciano  
agora nao tem erro, mas o play do debug mode fica desabilitado apos essas mudancas... e nao vejo o resultado completo....
 
Nova Entrada 29/11/2008 18:06
  linuxboy
20 tópicos
9th Level Poster


Re: tutorial mappy e xna do luciano  
Modificado Por linuxboy  em 30/11/2008 8:26:11)

no maplayer.cs este codigo abaixo apresenta erro... 


this.spriteBatch.Draw(this.TileStripTexture, new Vector2(i * this.TileWidth, j * this.TileHeight), this.GetTileSourceRectangle(this.Tiles[i][j].Id), Color.White);

Referência de objeto não definida para uma instância de um objeto.
 
Nova Entrada 30/11/2008 11:12
  lucianoJose
195 tópicos
Iniciante


Re: tutorial mappy e xna do luciano  
Modificado Por lucianoJose  em 30/11/2008 9:17:18)
 linuxboy escreveu

no maplayer.cs este codigo abaixo apresenta erro... 


this.spriteBatch.Draw(this.TileStripTexture, new Vector2(i * this.TileWidth, j * this.TileHeight), this.GetTileSourceRectangle(this.Tiles[i][j].Id), Color.White);

Referência de objeto não definida para uma instância de um objeto.


Oi linuxboy, tá dando referência nula nessa linha, mas, qual dos objetos está nulo?

De qualquer forma verifica se o método LoadContent está faltando fazer alguma das chamadas abaixo:

protected
override void LoadContent()
        {
            this.spriteBatch = new SpriteBatch(GraphicsDevice);
          
            this.Services.AddService(typeof(SpriteBatch), this.spriteBatch);
 
            this.mapLayer.LoadContent("TestLevel1.FMP", this.mappyLoader);
 
            this.mapLayer.TileStripTexture = this.Content.Load<Texture2D>("TileStrip");
 
            this.mapLayer.BuildSourceRectanglesTileStrip(3, 2, 5);
        }

@lucianoJoseBr My Blog: http://lucjose.wordpress.com
 
Nova Entrada 30/11/2008 12:19
  linuxboy
20 tópicos
9th Level Poster


Re: tutorial mappy e xna do luciano  
Modificado Por linuxboy  em 30/11/2008 10:54:21)

protected

{

 

override void LoadContent()// Create a new SpriteBatch, which can be used to draw textures.

 

 

 

 

 

 

 

 

myBase =

 

graphics.PreferredBackBufferWidth,

graphics.PreferredBackBufferHeight);

myBall =

 

graphics.PreferredBackBufferWidth,

graphics.PreferredBackBufferHeight);

graphics.PreferredBackBufferWidth = 800;

graphics.PreferredBackBufferHeight = 600;

graphics.ApplyChanges();

 

 

 

 

 

 

this.spriteBatch = new SpriteBatch(GraphicsDevice);this.Services.AddService(typeof(SpriteBatch), this.spriteBatch);this.mapLayer.LoadContent("mapa1.FMP", this.mappyLoader);this.mapLayer.TileStripTexture = this.Content.Load<Texture2D>("tilebloco");this.mapLayer.BuildSourceRectanglesTileStrip(3, 2, 5);new clsSprite(Content.Load<Texture2D>("base-arkanoide"),new Vector2(280f, 570f), new Vector2(64f, 64f),new clsSprite(Content.Load<Texture2D>("bolinha"),new Vector2(365f, 540f), new Vector2(64f, 64f),// Create a new SpriteBatch, which can be used to draw textures.

spriteBatch =

}

 

new SpriteBatch(GraphicsDevice);/// <summary>

 

/// UnloadContent will be called once per game and is the place to unload

 

/// all content.

 

/// </summary>


Begin must be called successfully before a Draw can be called.


 
Anterior Anterior
 
Próximo Próximo
  Forum  Criação de Jogo...  Gráficos 2D/3D  tutorial mappy e xna do luciano
Logos do XBox 360, XNA e Games For Windows
Copyright 2006-2012 por SharpgamesPolítica de Privacidade  |  Termos de Uso