I'm keeping this seperate from the base "Pascal and XNA" discussion as its effectivly the next step in making a game work.
XNA loads all resources through the ContentManager - this enables a single method of loading the game resources and makes it closely compatible with the XBox as the ContentManager is supported on the XBox360 as well.
In C# you add a graphic resource to the project - for example a PNG file. When the project is compiled a ".xnb" file is created for the resource. This .xnb file is the resource that needs to be distributed. Now I dont know how to compile the png/jpg to a .xnb but I can show how to load and display a xnb file.
I created a C# project - added a resource, and then copied the xnb file to my Pascal XNA project directory. In the example below the cursor is displayed on the screen. The resource file is saved in the XNADemo directory as Cursor.xnb
Code:
namespace XNADemo;
interface
uses
Microsoft.Xna.Framework,
Microsoft.Xna.Framework.Content,
Microsoft.Xna.Framework.Audio,
Microsoft.Xna.Framework.Graphics,
Microsoft.Xna.Framework.Input,
Microsoft.Xna.Framework.Storage;
type
TXNAGame = class(Microsoft.Xna.Framework.Game)
private
graphics : GraphicsDeviceManager;
// these are the size of the output window, ignored on Xbox 360
preferredWindowWidth : integer;
preferredWindowHeight : integer;
content : ContentManager;
SpriteEngine : SpriteBatch;
T : Texture2D;
protected
method Initialize; override;
method BeginRun; override;
method LoadGraphicsContent(loadAllContent: Boolean); Override;
method Update( gameTime : Gametime ); override;
method BeginDraw : boolean; override;
method Draw( gameTime : Gametime ); override;
method EndDraw; override;
public
constructor;
// Entry point into this object.
class method Main;
end;
implementation
constructor TXNAGame;
begin
inherited;
preferredWindowWidth := 800;//1280;
preferredWindowHeight := 600;//720;
Self.graphics := new Microsoft.Xna.Framework.GraphicsDeviceManager(Self);
Self.graphics.PreferredBackBufferWidth := preferredWindowWidth;
Self.graphics.PreferredBackBufferHeight := preferredWindowHeight;
Content := new ContentManager(Services);
end;
class method TXNAGame.Main;
begin
try
// probably should not be instantiating an object within itself :).
with lGame := new TXNAGame() do
lGame.Run();
except
on E: Exception do
begin
// MessageBox.Show(E.Message);
end;
end;
end;
method TXNAGame.Initialize;
begin
// Your Initialize Code here
Window.Title := 'Pascal and XNA';
inherited;
end;
method TXNAGame.BeginRun;
begin
// Your BeginRun Code here
inherited;
end;
method TXNAGame.Update( gameTime : Gametime );
begin
// Your Update Code here
inherited Update( gameTime );
end;
method TXNAGame.LoadGraphicsContent(loadAllContent: Boolean);
Begin
SpriteEngine := new SpriteBatch(graphics.GraphicsDevice);
T := Content.Load<Texture2D>('Cursor');
End;
method TXNAGame.BeginDraw : boolean;
begin
if not ( inherited BeginDraw ) then
begin
result := false;
exit;
end;
// Your BeginDraw Code here
result := true;
end;
method TXNAGame.Draw( gameTime : Gametime );
Var
V : Vector2;
begin
V := new Vector2(100,100);
graphics.GraphicsDevice.Clear( Color.CornflowerBlue );
SpriteEngine.Begin();
SpriteEngine.Draw(T,V,Color.White);
SpriteEngine.End();
inherited Draw( gameTime );
// Your Draw Code here
end;
method TXNAGame.EndDraw;
begin
// Your EndDraw Code here
inherited;
end;
end.
Note that xnd files are VERY big! A 66kb jpg file makes a 4mb xnb file that compresses in zip format to 1mb. Not exactly download friendly.
Bookmarks