PDA

View Full Version : Writing a better 2D engine. (Phoenix 2D Game Engine)



Pages : 1 [2]

Andreaz
14-06-2007, 02:26 PM
Yeah, it's progressing well, been coding like crazy on the tile engine and collision engine latly, there's some tricky parts that needs some trixxing to get working.

And no, this is the most official thread about it, i still consider Phoenix in late beta stage, theres a few more functions i want to finish before going 1.0

pstudio
14-06-2007, 03:01 PM
Sounds good. :D
Is it possible to try out the tile engine at current state?
Do you plan on adding many more features or are most of it ready?
It's really great (and so easy) so I would love to see this finished :D

btw. You have misnamed some classes (for instance: THPXImageSprite), but you probably already now ;)

Andreaz
14-06-2007, 04:29 PM
Sounds good. :D
Is it possible to try out the tile engine at current state?
Do you plan on adding many more features or are most of it ready?
It's really great (and so easy) so I would love to see this finished :D

btw. You have misnamed some classes (for instance: THPXImageSprite), but you probably already now ;)

There's a ]http://phoenixlib.net/files/TileDemo.zip[/url]

Howerver, i havn't really added any more to that as all the time of latly has been spent on the collisions.

And no, i actually missed that, really easy to miss, back side of copy-paste

DarknessX
15-06-2007, 02:58 PM
Is this engine capable of being used in a game as it is right now? I'm thinking of using it, as it seems to be a pretty good engine.

Basically, what I need:

Collisions : Pokemon (Gameboy.. Pokemon Red/Blue) style... When 2 people walk into each other, they will be in a battle.

Movement: Pokemon (Gameboy.. Pokemon Red/Blue) style...

Graphics: Pokemon (Gameboy.. Pokemon Red/Blue) style...

Basically everything is going to be Pokemon style. I'm going to make an RPG game, both single-player and online multiplayer (online mp will be an MMORPG game) using all pokemon style stuff. But the game will be slightly more complex than that, as you will be able to build your own towns and etc in certain regions (even on the MMORPG part) and wars, kingdom building, economy will be a big part of the game. Fighting will be common place, and the leveling up will be mostly realistic, as in the more you use certain things, the more you level them up. In fighting, strategy, stealth, and technique will all be necessary to win... Weapon styles will be sword, bows, daggers, javelins, magic, etc. Almost everything available in single player will be available in multiplayer, and when your character dies, your control passes on to the next available family member. Age limits your capabilities (but no worries, while you are online, your character grows quickly, while offline slowly) and you will gain inheritances when you go to the next person. Families will be a big part of the game, aswell...


Also, would like to say, on FreePascal 2.0.4, in file phxlogger.pas, on line 157, you had:
{$ifdef fpc} inline; {/ifdef}

This provides an error while attempting to compile the sprites demo.

Also, I'm having difficulties compiling after removing the 'inline' call:


First compilation of c:\projects\pheonix\demo\sprites\main.pas
phxScreen.pas&#40;454,47&#41; Error&#58; Incompatible type for arg no. 1&#58; Got "<address>", expected "<procedure>"
phxScreen.pas&#40;455,46&#41; Error&#58; Incompatible type for arg no. 1&#58; Got "<address>", expected "<procedure>"
phxScreen.pas&#40;521,42&#41; Error&#58; range check error while evaluating constants
phxScreen.pas&#40;593&#41; Fatal&#58; There were 3 errors compiling module, stopping
phxScreen.pas&#40;33,15&#41; Fatal&#58; Compilation aborted

Andreaz
18-06-2007, 05:30 AM
Is this engine capable of being used in a game as it is right now? I'm thinking of using it, as it seems to be a pretty good engine.

Well, parts of it are atleast, more or less everything exept the tile engine are done, the package had a overhaul since the last release aswell, but that isnt a feature thats needed at once.

What's mostly holding back the progress of the tile engine is the trouble i'm having with the collision engine, detection is working well, however responces arent, alot of stuff that needs to be tested and i havn't been able to figure it out yet..

I might do a quick workaround using subdivisions to get somewhat accurate results, atleast as a start, thus it could be changed later on without to much extra work...



Also, would like to say, on FreePascal 2.0.4, in file phxlogger.pas, on line 157, you had:
{$ifdef fpc} inline; {/ifdef}

This provides an error while attempting to compile the sprites demo.

Also, I'm having difficulties compiling after removing the 'inline' call:


First compilation of c&#58;\projects\pheonix\demo\sprites\main.pas
phxScreen.pas&#40;454,47&#41; Error&#58; Incompatible type for arg no. 1&#58; Got "<address>", expected "<procedure>"
phxScreen.pas&#40;455,46&#41; Error&#58; Incompatible type for arg no. 1&#58; Got "<address>", expected "<procedure>"
phxScreen.pas&#40;521,42&#41; Error&#58; range check error while evaluating constants
phxScreen.pas&#40;593&#41; Fatal&#58; There were 3 errors compiling module, stopping
phxScreen.pas&#40;33,15&#41; Fatal&#58; Compilation aborted


Hmm, well fpc seems to **** up inine functions from now and then, maybe not the most stable feature in fpc.. Just remove it..

DarknessX
18-06-2007, 08:46 PM
Thats what I did. Well, thanks for the confirmation, cause once I'm done this little side project I'm working on with Jedi-SDL, I'm gonna make an rpg game with this... If I can make it compile properly.

Andreaz
21-06-2007, 06:03 AM
It should compile quite easy i think, I just hadn't the time to try the last release enough in fpc, but the version before that worked fine so it should be quite easy

Sesilla
26-06-2007, 04:10 PM
Hi all,

when i compile the Phoenix Particle Demo i have this errors:

Gravity:= Vector2f(0, 0); --> Incompatible types: ' Single and TVector2f'
Undeclared identifier: 'Blend'
Undeclared identifier: 'bmOne'.

Why
Thanks in advance
Sesilla

Andreaz
27-06-2007, 04:53 AM
Yeah, i've changed a few things in the particle editor but not in the demo, saw that a few days ago, here's a fixxed demo;

http://phoenixlib.net/files/Particles.zip

Traveler
20-07-2007, 04:04 PM
Hi Andreaz,

I've downloaded your latest version (dated april 2007) today and I came across a couple errors/problems while compiling the demos.

The Canvas demo finalizes immediately after starting. The log file doesn't say a whole lot more than that either, I'm afraid.

In several demo's (sprites for example) an error in file phxTexture.pas at line 1446 appears saying incompatible types: 'FIBitmap' and PFIBitmap.

Anyway, it still seems like a very promising project, I hope you're continuing the work :)

Andreaz
25-07-2007, 06:06 PM
Hi Andreaz,

I've downloaded your latest version (dated april 2007) today and I came across a couple errors/problems while compiling the demos.

The Canvas demo finalizes immediately after starting. The log file doesn't say a whole lot more than that either, I'm afraid.

In several demo's (sprites for example) an error in file phxTexture.pas at line 1446 appears saying incompatible types: 'FIBitmap' and PFIBitmap.

Anyway, it still seems like a very promising project, I hope you're continuing the work :)

The canvas problem; probably some kind of nullpointer exception i've overlooked, they dont show in the log.

For the pxhTexture problem, compiler and version ?

Traveler
26-07-2007, 09:21 AM
For the pxhTexture problem, compiler and version ?

Delphi 7 PE

Andreaz
26-07-2007, 05:59 PM
Hmm, okey. That makes no sence since i've doing the dev in D7, and that version was kindof rushed the final stages to get it working.

I have coded alot since then so it may be helped, and yes it's getting close to 1.0, more or less all the features for v1.0 is implemented, only left some testing and debugging.

I have to fix the homepage aswell, but time... gash !

crackmeal
02-08-2007, 09:14 AM
I've been getting to know this lib recently and demos are fantastic. I plan to use some free time here and there to work on a 2D shooter. So far I have designed my own ship, dropped in a makeshift starfield using an off-screen particle fountain, ship movement, and basic bullets are working.

http://upload2.postimage.org/79009/deepshooter.jpg (http://upload2.postimage.org/79009/photo_hosting.html)

I'm looking forward to grasping the collision detection, which I understand is even capable of dealing with rotation. Also, I wouldn't mind getting a demo of loading a .phxmap, smoothly scrolling it, etc... though I'm sure this is part of the delay for 1.0 since most of the Tiles stuff I've tested seemed the least polished of the demos.

Andreaz, thanks for creating a such a cool 2D library for Delphi/Pascal. I'm sure I'm not the only one looking forward to your next big update. :wink:

Andreaz
05-08-2007, 09:27 PM
I've been getting to know this lib recently and demos are fantastic. I plan to use some free time here and there to work on a 2D shooter. So far I have designed my own ship, dropped in a makeshift starfield using an off-screen particle fountain, ship movement, and basic bullets are working.

http://upload2.postimage.org/79009/deepshooter.jpg (http://upload2.postimage.org/79009/photo_hosting.html)

I'm looking forward to grasping the collision detection, which I understand is even capable of dealing with rotation. Also, I wouldn't mind getting a demo of loading a .phxmap, smoothly scrolling it, etc... though I'm sure this is part of the delay for 1.0 since most of the Tiles stuff I've tested seemed the least polished of the demos.

Andreaz, thanks for creating a such a cool 2D library for Delphi/Pascal. I'm sure I'm not the only one looking forward to your next big update. :wink:

Yeah, the rotating collisions will be in 1.0, not that shure about the tile engine through, there's alot of considerations for the tiles that i havn't decided yet.

But if there's interest i can release the code-so-far of that one aswell...

Robert Kosek
05-08-2007, 10:00 PM
But if there's interest i can release the code-so-far of that one aswell...
inc(interest);

I am even more interested because of the words "rotating collision." I downloaded and tried the binaries just yesterday and was really impressed. Rotating collisions will just be icing on the cake. :D

I'm seriously thinking of working with Phoenix now. Cross platform things are more interesting with the advent of Vista I must say.

pstudio
05-08-2007, 10:06 PM
But if there's interest i can release the code-so-far of that one aswell...
There is an interest :D

I started on a game in Phoenix, but decided to put in on hold, waiting to see what the upcomming release of Phoenix can do for it.

I would personally like to see how much progress you've done since the last release, and I'm pretty sure there are others who agree with me :)

Robert Kosek
06-08-2007, 08:44 PM
Hey Andreaz, are you using FastGEO (http://www.partow.net/projects/fastgeo/index.html) for collision detection? It might really help you accelerate the inclusion of collision detection of all types and let you get back to finishing off version 1.0! ;)

WILL
07-08-2007, 01:04 AM
How many demos/examples are there available for this library now? If you have a few 'mini' games a showcase page might be a great way to 'display' them all to attract interest.

The eyes are the strongest of all our 5 senses, no? ;)

Andreaz
07-08-2007, 02:01 PM
Hey Andreaz, are you using FastGEO (http://www.partow.net/projects/fastgeo/index.html) for collision detection? It might really help you accelerate the inclusion of collision detection of all types and let you get back to finishing off version 1.0! ;)

No, i'm using a custom build engine based on the Seperating Axis Theorem with support for polygons and circles, more primitives may come if needed.

The collision responces arent 100% working and will not be in 1.0, it's really hard getting accurate results in this section. (However not many libs supports even rotating collision objects so i'm quite pleased with the result nontheless).

But FastGEO may prove usefull in the future!


How many demos/examples are there available for this library now? If you have a few 'mini' games a showcase page might be a great way to 'display' them all to attract interest.

The eyes are the strongest of all our 5 senses, no? ;)

There's a 10 demos or so avaiable for now, i have a few game demos in the making, it takes alot of time creating graphics and such through.

I have spent some time latly on improving the various editors, a brand new font editor, improvments to the image editor, gui etc.

The last few days i've been going over all sources to make shure it compiles in fpc aswell as delphi 7 and making shure the demos has up do date projects for both compilers.

I'm spending a few days at the beach now as finally the summer weather has catched up with us here in sweden, have two veeks vacation left and my intention is to have 1.0 relased before that is over :)

And finally the status of the Tile engine is as follows; more or less the thing that is done so far is the rendering and layer handling, and only for normal rectangular grids, havn't really came up with a good way of handling isometric grids and collisions and such... It's easy to design a tile engine for a specific game, alot more troublesome to make one dynamic enough to support rpg's platforms and isometric games at once :)

Thanks for all the post through, it really gives one more enery and will to work on the lib's when people discusses is!

Andreas over and out!

Robert Kosek
07-08-2007, 03:20 PM
Well, I'm glad to hear that you have made progress. Don't freeze your toes in the water. ;)

I am thinking of switching to Phoenix fully because the latest version of Asphyre has become too complex, and I want to start incorporating the ability to go cross platform. The latter can triple an audience, and for casual games that can mean success. Because I'm not aiming for ritzy graphics or effects, and not having the budget for such, Phoenix is the best bet.

I love how well you have followed the KISS (keep it simple, stupid) principle. It makes it easier on guys like me. :D

jdarling
07-08-2007, 04:30 PM
And finally the status of the Tile engine is as follows; more or less the thing that is done so far is the rendering and layer handling, and only for normal rectangular grids, havn't really came up with a good way of handling isometric grids and collisions and such... It's easy to design a tile engine for a specific game, alot more troublesome to make one dynamic enough to support rpg's platforms and isometric games at once :)

Andreaz, you might want to take a look at how I handled this in GIE (full source and exe at: http://www.eonclash.com/ViewProduct.php?ProductID=15)
Basically I provide for an X and Y offset and an X odd offset that is added to the tile base position. This allows you to edit and preview square, iso, and hex tiles easily within GIE. Granted this only gets you stagger maps for ISO and Hex, but you can also add a rendering flag that states how the step should occur.

Its been a long time since I played with GIE, but I think I remember enough of the code to explain it if it doesn't make any sense. The down side is that its a Delphi application and not an FPC application :)

wagenheimer
08-08-2007, 01:59 AM
So, Robert Kosek, i was some time ago finished the second game, using the Phoenix Engine, Abra Academy, but for windows, i did have problems with the portals that did not see with good eyes OpenGL games for Windows. =(. So i did have to convert all my game to Direct3D, and i did use Asphyre 4 for that. My first ideia was first to try to convert Phoenix to be Also Direct3D Compatible, but my time was low, and i did give up, and i did do some frankstein convertions to make the game Asphyre Compatible (I Did converted the GuiEditor, Path Moves).

But for Mac, OpenGL is the only viable engine.

I want to convert my game to be Mac compatible, somebody here did compiled sucefully Phoenix on a Mac? I think that if Phoenix goes fine on Mac, it´s not so hard to create some "conversion routines" that will make a simple conversion between Asphyre and Phoenix possible source codes....

Robert Kosek
08-08-2007, 02:12 PM
I honestly don't like working with DirectX, no matter how nice it looks. There is so much grunt work to do to even load a texture and draw it on the screen that it isn't funny. I've worked with OpenGL (http://img109.imageshack.us/my.php?image=screenshot23fr.jpg) (anyone who remembers my Pascal Rocks! wallpaper saw some of the source for this) for a long time even though I'm not particularly good at 3D math; I can work with and enhance Phoenix far more than I can Asphyre.

Graphics are overrated to an extent. If it is the selling point of your game then you certainly need them. However, when people still play Stars! (http://en.wikipedia.org/wiki/Stars%21) and hope for a sequel, any sequel, the absolute last thing on their mind is graphics. It is all in the game, the strategy, the challenge. I won't rant, but I wrote on this recently (http://thewickedflea.com/blog/2007/07/strategy-in-games-and-universe-at-war/) in my blog about Petroglyph's new RTS, their failure with EaW, and how an ancient (and now completely ugly) game totally trumped them.

The more I read about Phoenix and browse the source code, the more I like. Making the library act like the standard Delphi canvas is pure genius.

Robert Kosek
08-08-2007, 03:41 PM
Proof that using Phoenix is easy:

I wrote a testbed incorporating a turnable freighter in 20 minutes from the included template in Turbo Delphi. I took an image I knew of that was 20 frames worth of rotation, turned it into a PNG and then made it into a 5x4 grid. 4 minutes of processing. Getting the basic template working took a little more effort as I forgot to copy the DLLs. I easily got my image in, rotating, and my framerate appearing in the window title within in under about 10 minutes. The delay was caused by a minor bug I can't quite track down (showing the frame rate hid the freighter somehow). After that I included a fullscreen toggle in no time at all, complete with reloading images and so on.

It totals only 90 lines and is really easy to understand. It even averages 5,300FPS. :D

Sum total I learned to use the images, input, screen, and timer objects in less than 30 minutes. Now I'm starting to get ready to have a bit more fun in making something that is more of an actual game.

Here's my code for those interested:
unit Main;

&#123;$IFDEF FPC&#125;
&#123;$mode objfpc&#125;&#123;$H+&#125;
&#123;$ENDIF&#125;

interface

uses
Classes, SysUtils, Math,

phxBase,
phxScreen,
phxImages,
phxInput,
phxTimer;


procedure MainLoop;

implementation

//------------------------------------------------------------------------------
procedure MainLoop;
const
TurnSpeed = 12;
var Screen&#58; TPHXScreen;
Image&#58; TPHXImage;
KeyBoard&#58; TPHXKeyboard;
Timer&#58; TPHXTimer;

Rotation&#58; Single;
Switched&#58; Boolean;
begin
// Get the window
Screen &#58;= TPHXScreen.getInstance&#40;&#41;;
Screen.VSync &#58;= True;
KeyBoard &#58;= TPHXKeyboard.Create;
Timer &#58;= TPHXTimer.Create;

// Open the window
if not Screen.Open&#40;'Rotating Freighter Example', -1, -1, 800, 600&#41; then Exit;

Image &#58;= TPHXImage.Create;
Image.LoadImage&#40;'robominer.png'&#41;;
Image.UpdatePatterns&#40;128,128&#41;;

Rotation &#58;= 0;
Switched &#58;= False;

repeat
KeyBoard.Update;
if &#40;KeyBoard.Keys&#91;VK_RALT&#93; and KeyBoard.Keys&#91;VK_RETURN&#93;&#41; and &#40;not Switched&#41; then begin
Screen.Close;
Screen.Fullscreen &#58;= not Screen.Fullscreen;
Screen.Update;
Screen.Open;
Image.Clear;
Image.LoadImage&#40;'robominer.png'&#41;;
Image.UpdatePatterns&#40;128,128&#41;;
Switched &#58;= True;
end else if not &#40;KeyBoard.Keys&#91;VK_RALT&#93; and KeyBoard.Keys&#91;VK_RETURN&#93;&#41; then
Switched &#58;= False;

Timer.Update;
if Timer.FrameCount mod 50 = 0 then
Screen.Title &#58;= Format&#40;'Rotating Freighter Example &#91;%dFPS&#93;',&#91;Timer.FrameRate&#93;&#41;;

// Clear the window
Screen.Clear&#40;&#41;;

// Turn the ship! Woo!
if KeyBoard.Keys&#91;VK_LEFT&#93; then
Rotation &#58;= Rotation - TurnSpeed*Timer.FrameTime;
if KeyBoard.Keys&#91;VK_RIGHT&#93; then
Rotation &#58;= Rotation + TurnSpeed*Timer.FrameTime;

if Rotation <0> 359 then
Rotation &#58;= Rotation - 359;

Image.Draw&#40;336,236, Trunc&#40;Rotation&#41; mod 20&#41;;

// Flip the buffers
Screen.Flip&#40;&#41;;
until &#40;Screen.Visible = False&#41;;
end;

end.

Andreaz
08-08-2007, 07:06 PM
Proof that using Phoenix is easy:

I wrote a testbed incorporating a turnable freighter in 20 minutes from the included template in Turbo Delphi. I took an image I knew of that was 20 frames worth of rotation, turned it into a PNG and then made it into a 5x4 grid. 4 minutes of processing. Getting the basic template working took a little more effort as I forgot to copy the DLLs. I easily got my image in, rotating, and my framerate appearing in the window title within in under about 10 minutes. The delay was caused by a minor bug I can't quite track down (showing the frame rate hid the freighter somehow). After that I included a fullscreen toggle in no time at all, complete with reloading images and so on.

It totals only 90 lines and is really easy to understand. It even averages 5,300FPS. :D

Sum total I learned to use the images, input, screen, and timer objects in less than 30 minutes. Now I'm starting to get ready to have a bit more fun in making something that is more of an actual game.

Here's my code for those interested:

Great work Robert, there's thing there even i havnt considered, like switching fullscreen, there was a lot of work in glxtreem to make that work good.

And what i think you wull like is that you can shawe of 5 mins of the work in the above project just from the enhancements in the new version :),

1. No need for the (not Switched) anymore: The input supports removing states: KeyBoard.States:= KeyBoard.States - [isButton32];
2. Image editor is alot bettter, much easier to add the patterns, no need to update the matterns manually (or even considering the size, just throw em into the image and define the patterns by easy point and drag!)

One thing to note through, shure the canvas class is nice but be warned that it lacks in performance through, there's no possibility to cache the geometry as there is in the imagelist. But for simple games, like minesweeper and such it will be sufficient!

And latly, no need to say phx doesnt support fancy graphics, it does, thrust me, you can throw all sorts of cool pixelshaders and fancy effects if you'd really like (pixelshader support is a planned feature btw! And the particle engine is top notch aswell if i may say so, havn't seen many other s out there that matches what it can do and with the speed it does it (it's the fifth or so particle engine i made)

Great to hear phx works in turbo delphi aswell, please let me know if you runs into any problems!

Thanks for the great feedback and keep up the good work, i really look forward to what you can sqeeze out of my lib!

(And btw, you forgot to free the imagelist and keyboard in your project, a common issue in my demos aswell, memory leeks is for everyone!)

Robert Kosek
08-08-2007, 07:18 PM
Mmm... true. But leaking 4kb of ram out of 2gb available just makes Windows work a little. :P (I'd never write it that way in a SERIOUS application. This was just thrown together to see how fast I could do it.)

From what I've seen the particle system is excellent even though you don't include negative growth (shrinkage) in the editor. ;) I've not written a real particle system myself, but I'd love to see a percentile timer on the color list so you can set the lifetime of the colors. Think of a propane flame and you see a bright semi-clear white-blue that quickly fades to a bright azure tip that is smaller. I'd also ask that you can spawn a particle system/effect in a given direction.

Overall your work is quite excellent, and while the canvas might not be optimized it provides a good example base foundation for those who like the "geometry wars" look alike games. (Not that I'm one, but hey.)

Maybe we could even get side or top down rendering of models implemented. Then we could imitate games like Flatspace (http://www.treality.freeserve.co.uk/flatspaceii.html), etc.

jdarling
08-08-2007, 07:49 PM
Andre, you should consider using a modified factory framework where all objects in Phoenix add themselves to a list and upon the application existing it automatically cleans up any that were forgot and writes it to a log. That way devs have a quick and easy one stop to see what they forgot to free :). I do this in JS and it works like a charm. Especially since in JS many of the objects are created in a script and can easily be lost in the shuffle.

Andreaz
08-08-2007, 07:59 PM
Mmm... true. But leaking 4kb of ram out of 2gb available just makes Windows work a little. :P (I'd never write it that way in a SERIOUS application. This was just thrown together to see how fast I could do it.)

Hehe, so true ;)


From what I've seen the particle system is excellent even though you don't include negative growth (shrinkage) in the editor. ;) I've not written a real particle system myself, but I'd love to see a percentile timer on the color list so you can set the lifetime of the colors. Think of a propane flame and you see a bright semi-clear white-blue that quickly fades to a bright azure tip that is smaller. I'd also ask that you can spawn a particle system/effect in a given direction.

Negataive growth is supported ofc, could call it a editor bug :)

The color list is more or less percentive based, if you say add two blue and two white it's blue the first 33% of its life, then ut fades to white and are white the last 33%. I had a time based version there for a while until i realized that i have a variance in the particles life times, tus a fixed time for each color wasnt good enough. But you can add alot of colors to fade between to get just the effect you want.

There's a spread and direction variable for just that :)



Overall your work is quite excellent, and while the canvas might not be optimized it provides a good example base foundation for those who like the "geometry wars" look alike games. (Not that I'm one, but hey.)

Yeah, ofcourse just wanted to let you know that using the canvas calls to render alot of stuff really isnt the way to go. Better to render the canvas stuff into a displaylist and then just rendering the displaylist instead. New feature discovered!



Maybe we could even get side or top down rendering of models implemented. Then we could imitate games like Flatspace (http://www.treality.freeserve.co.uk/flatspaceii.html), etc.
That was actually a great idea, consider it added to the todo list, not for 1.0 ofc :) Have alot of this done for glxtreem already, so its quite easy to port and modify for phx, even through theres some optimizations and reorginisation i want to do for the meshes.

Robert Kosek
08-08-2007, 08:09 PM
There's a spread and direction variable for just that :)Yeah, but that's in the effect "template" and not the system. Say I want a meteor trail that looks the same but I want it to emit in a different direction each time. Right now there's no way I can say
ParticleSystem.Direction := -90;
or
ParticleSystem := ParticleManager.Emit('bang',x,y,angle);
so I can "trail" the meteor object. Or at least not that I've found. I'm still reading your source code to learn everything.

I really look forward to the next version! :D

Andreaz
08-08-2007, 08:33 PM
There's a spread and direction variable for just that :)Yeah, but that's in the effect "template" and not the system. Say I want a meteor trail that looks the same but I want it to emit in a different direction each time. Right now there's no way I can say
ParticleSystem.Direction := -90;
or
ParticleSystem := ParticleManager.Emit('bang',x,y,angle);
so I can "trail" the meteor object. Or at least not that I've found. I'm still reading your source code to learn everything.

I really look forward to the next version! :D

No that is true, it's per effect, but its possible to circumvent that by changing the particle effect parameters before calling the particlesystems update function, it always uses the parameters stored in the effect, and you can change the effect at any time.

The particles only inherits the position of the parent system, i'm not really shure how to handle inheriting a direction aswell, theres no clear way of interpolating the spread or the direction of the effect to the one in the system.

Maybe some kind of vector that can be used to add to the resulting velocity vector for the particle could solve that;


Particle.velocity.X&#58;= Particle.Velocity.X + System.EmitVector.X;


jdarling, that could be a quite nice way to do it, if it's necessary, most phx objects handles the memory already, sprites, images, fonts, events and such, only the components themselves that doesnt. So only stuff that needs freeing is the imagelists, fontlists inputs and so forth.

Robert Kosek
09-08-2007, 02:44 PM
Hey Andreaz, would you test the following code for me and tell me if it works? In Turbo Delphi the game crashes as though the window isn't even shown. Only the particle system appears to do this, yet no error is raised! You can use a placeholder image for the sprite; it is just a round glow particle.

When I comment out the effect the application runs. Turn the effect addition code on and when it closes there's an invalid pointer operation error pointing nowhere. But as soon as I turn on the random additions of particles the application crashes like a rock! :s

Maybe you can find something I can't. (Also, the colors aren't object oriented like the particle example, so you might've weeded it out already. I can't tell with this past version.)

Edit
This exception seems to be the killer right here:
10&#58;51&#58;07 AM Error!&#58; Access violation at address 00430230 in module 'GravityBombs.exe'. Read of address 00000004

The problem is right here (last line):
//------------------------------------------------------------------------------
function TPHXParticleManager.AddSystem&#40;Effect&#58; String; X, Y&#58; Single&#41;&#58; TPHXParticleSystem;
var System&#58; TPHXParticleSystem;
begin
System&#58;= TPHXParticleSystem.Create&#40;Self&#41;;
System.Effect &#58;= Effects.Find&#40;Effect&#41;;And traced to (the for loop declaration):
function TPHXImageList.IndexOf&#40;const Name&#58; String&#41;&#58; Integer;
var Index&#58; Integer;
begin
for Index&#58;=0 to FImages.Count - 1 do begin
if TPHXImage&#40;FImages&#91;Index&#93;&#41;.Name = Name then begin
Result&#58;=Index;
Exit;
end;
end;
Result&#58;=-1;
end;

Andreas!! The error is that you aren't creating an imagelist! Searching a nil pointer for a string is a painful crash. Goodness, there isn't even a parameter to pass one to the particle manager's constructor. I hope you've got an updated copy on hand. :lol:


I've updated the sourcecode and it is semistable now, but it still closes with that invalid pointer op message. :s At least I can see the effect now.

unit Main;

&#123;$IFDEF FPC&#125;
&#123;$mode objfpc&#125;&#123;$H+&#125;
&#123;$ENDIF&#125;

interface

uses
Classes, SysUtils,
phxBase,
phxImages,
phxParticles,
phxInput,
phxTimer,
phxMath,
phxClasses,
phxLogger,
phxScreen;

const
Gravity&#58; TVector2f = &#40;x&#58; 0; y&#58; -9.81&#41;; // Gravitic Constant of Earth in M/Sec^2 &#40;Velocity&#41;


procedure MainLoop;

implementation

//------------------------------------------------------------------------------
procedure MainLoop;
var Screen&#58; TPHXScreen;
Particles&#58; TPHXParticleManager;
Mouse&#58; TPHXMouse;
Keyboard&#58; TPHXKeyboard;
Timer&#58; TPHXTimer;

i,l&#58; Word;
begin
// Get the window
Screen &#58;= TPHXScreen.getInstance;
Particles &#58;= TPHXParticleManager.Create;
Mouse &#58;= TPHXMouse.Create;
Timer &#58;= TPHXTimer.Create;
Keyboard &#58;= TPHXKeyboard.Create;

Screen.VSync &#58;= True;
Screen.DepthBits &#58;= 32;
// Open the window
if not Screen.Open&#40;'Gravity Bombs', -1, -1, 800, 600&#41; then begin
TPHXLogger.getInstance.Log&#40;logSevere, 'Main', 'Unable to initialize form.'&#41;;
Exit;
end;

// with Particles.Effects.Add do begin
// TPHXLogger.getInstance.Log&#40;logInfo, 'Main', 'Loading comet particle...'&#41;;
// LoadFromFile&#40;'comet.phxpar'&#41;;
// Name &#58;= 'Comet';
// GrowthMin &#58;= -16;
// GrowthMax &#58;= -16;
// Texture &#58;= 'particle.png';
// end;

if not Assigned&#40;Particles.Images&#41; then begin
Particles.Images &#58;= TPHXImageList.Create;
TPHXLogger.getInstance.Log&#40;logWarning, 'Main', 'Imagelist is nil; initializing.'&#41;;
end;
Particles.Images.LoadImage&#40;'particle.png'&#41;.UpdateP atterns;

l &#58;= 0;

with Particles.Effects.Add do begin
Name &#58;= 'Comet';
Quota &#58;= 500;
EmissionRate&#58;= 100;
Texture &#58;= 'particle.png';
Blending &#58;= bmAdd;
DurationMin &#58;= 0.50;
DurationMax &#58;= 0.75;
Direction &#58;= -90;
SpreadMin &#58;= 360;
SpreadMax &#58;= 360;
VelocityMin &#58;= 72;
VelocityMax &#58;= 84;
TimeToLiveMin &#58;= 0.5;
TimeToLiveMax &#58;= 0.5;
SizeMin &#58;= 32;
SizeMax &#58;= 32;
GrowthMin &#58;= -12;
GrowthMax &#58;= -16;
NumColors &#58;= 3;
Colors&#91;0&#93; &#58;= Color4f&#40;0.7,0.8,1.0,0.6&#41;;
Colors&#91;1&#93; &#58;= Color4f&#40;0.6,0.7,0.9,0.6&#41;;
Colors&#91;2&#93; &#58;= Color4f&#40;0.1,0.2,0.5,0.6&#41;;
end;

Randomize;

repeat
Timer.Update;
Mouse.Update;
Keyboard.Update;

if Random&#40;200&#41; <100> 0 then
for I &#58;= 0 to Particles.Count - 1 do
with Particles.Systems&#91;i&#93; do begin
Position &#58;= VectorSub&#40;Position,VectorMul&#40;Gravity,Timer.FrameTi me&#41;&#41;;
if Position.Y > 650 then
Particles.RemoveSystem&#40;Particles.Systems&#91;i&#93;&#41;;
end;

Particles.Move&#40;Timer.FrameTime&#41;;

if l <> Particles.Count then begin
l &#58;= particles.Count;
Screen.Title &#58;= Format&#40;'Gravity Bombs &#91;%d active particle systems&#93;',&#91;l&#93;&#41;;
end;

// Clear the window
Screen.Clear;

Particles.Render;

// Flip the buffers
Screen.Flip;
until &#40;Screen.Visible = False&#41;;

Particles.Images.Free;
Particles.Free;
Keyboard.Free;
Mouse.Free;
Timer.Free;
Screen.Free;
end;

end.

Andreaz
10-08-2007, 03:00 PM
Andreas!! The error is that you aren't creating an imagelist! Searching a nil pointer for a string is a painful crash. Goodness, there isn't even a parameter to pass one to the particle manager's constructor. I hope you've got an updated copy on hand. :lol:


Me ?

Hehe, anyway in the particle demo i have the following (not shure its changed alot since the april version either)


Images&#58;= TPHXImageList.Create;
Images.LoadImage&#40;'Circle.png'&#41;;
Images.LoadImage&#40;'Spark.png'&#41;;
Images.LoadImage&#40;'Fire.png'&#41;;


ParticleManager&#58;= TPHXParticleManager.Create;
ParticleManager.Images&#58;= Images;

There, imagelist assigned to the particle manager and ready :P

And to note, all components that uses imagelists, fonts or any other resource requires the user to bind the list to the component, so you may run into the same thing again.




unit Main;

&#123;$IFDEF FPC&#125;
&#123;$mode objfpc&#125;&#123;$H+&#125;
&#123;$ENDIF&#125;

interface

uses
Classes, SysUtils,
phxBase,
phxImages,
phxParticles,
phxInput,
phxTimer,
phxMath,
phxClasses,
phxLogger,
phxScreen;

const
Gravity&#58; TVector2f = &#40;x&#58; 0; y&#58; -9.81&#41;; // Gravitic Constant of Earth in M/Sec^2 &#40;Velocity&#41;


procedure MainLoop;

implementation

//------------------------------------------------------------------------------
procedure MainLoop;
var Screen&#58; TPHXScreen;
Particles&#58; TPHXParticleManager;
Mouse&#58; TPHXMouse;
Keyboard&#58; TPHXKeyboard;
Timer&#58; TPHXTimer;

i,l&#58; Word;
begin
// Get the window
Screen &#58;= TPHXScreen.getInstance;
Particles &#58;= TPHXParticleManager.Create;
Mouse &#58;= TPHXMouse.Create;
Timer &#58;= TPHXTimer.Create;
Keyboard &#58;= TPHXKeyboard.Create;

Screen.VSync &#58;= True;
Screen.DepthBits &#58;= 32;
// Open the window
if not Screen.Open&#40;'Gravity Bombs', -1, -1, 800, 600&#41; then begin
TPHXLogger.getInstance.Log&#40;logSevere, 'Main', 'Unable to initialize form.'&#41;;
Exit;
end;

// with Particles.Effects.Add do begin
// TPHXLogger.getInstance.Log&#40;logInfo, 'Main', 'Loading comet particle...'&#41;;
// LoadFromFile&#40;'comet.phxpar'&#41;;
// Name &#58;= 'Comet';
// GrowthMin &#58;= -16;
// GrowthMax &#58;= -16;
// Texture &#58;= 'particle.png';
// end;

if not Assigned&#40;Particles.Images&#41; then begin
Particles.Images &#58;= TPHXImageList.Create;
TPHXLogger.getInstance.Log&#40;logWarning, 'Main', 'Imagelist is nil; initializing.'&#41;;
end;
Particles.Images.LoadImage&#40;'particle.png'&#41;.UpdateP atterns;

l &#58;= 0;

with Particles.Effects.Add do begin
Name &#58;= 'Comet';
Quota &#58;= 500;
EmissionRate&#58;= 100;
Texture &#58;= 'particle.png';
Blending &#58;= bmAdd;
DurationMin &#58;= 0.50;
DurationMax &#58;= 0.75;
Direction &#58;= -90;
SpreadMin &#58;= 360;
SpreadMax &#58;= 360;
VelocityMin &#58;= 72;
VelocityMax &#58;= 84;
TimeToLiveMin &#58;= 0.5;
TimeToLiveMax &#58;= 0.5;
SizeMin &#58;= 32;
SizeMax &#58;= 32;
GrowthMin &#58;= -12;
GrowthMax &#58;= -16;
NumColors &#58;= 3;
Colors&#91;0&#93; &#58;= Color4f&#40;0.7,0.8,1.0,0.6&#41;;
Colors&#91;1&#93; &#58;= Color4f&#40;0.6,0.7,0.9,0.6&#41;;
Colors&#91;2&#93; &#58;= Color4f&#40;0.1,0.2,0.5,0.6&#41;;
end;

Randomize;

repeat
Timer.Update;
Mouse.Update;
Keyboard.Update;

if Random&#40;200&#41; <100> 0 then
for I &#58;= 0 to Particles.Count - 1 do
with Particles.Systems&#91;i&#93; do begin
Position &#58;= VectorSub&#40;Position,VectorMul&#40;Gravity,Timer.FrameTi me&#41;&#41;;
if Position.Y > 650 then
Particles.RemoveSystem&#40;Particles.Systems&#91;i&#93;&#41;;
end;

Particles.Move&#40;Timer.FrameTime&#41;;

if l <> Particles.Count then begin
l &#58;= particles.Count;
Screen.Title &#58;= Format&#40;'Gravity Bombs &#91;%d active particle systems&#93;',&#91;l&#93;&#41;;
end;

// Clear the window
Screen.Clear;

Particles.Render;

// Flip the buffers
Screen.Flip;
until &#40;Screen.Visible = False&#41;;

Particles.Images.Free;
Particles.Free;
Keyboard.Free;
Mouse.Free;
Timer.Free;
Screen.Free;
end;

end.

I've changed how the particle systems is managed by the manager, uses a standard TList now instead, should help on that error.


Oh, and theres no need to call UpdatePatterns when loading an image, it's done automatically ;) Only needed if you change the patterns manually!

Robert Kosek
10-08-2007, 03:07 PM
Okay. I didn't expect all that in the beginning, so I had to work and troubleshoot my way through the whole thing. Other than the annoyance at being lost for a little bit, I looked right past the imagelist creation in the sample, it works pretty well.

You need to regen the documentation though, since I noticed that the particle system has documentation but not in what is generated. ;)

Here's a template contribution for you. I don't know how FPC handles exceptions, but this forces all exceptions to be logged via Phoneix's internal logger. However if FPC/Lazarus supports exception catching along these lines then this will work just fine and dandy.


program Template;

&#123;$APPTYPE CONSOLE&#125;

uses
SysUtils,
Main,
&#123;$IFNDEF FPC&#125;
&#123;$IFDEF WINDOWS&#125;
Windows,
&#123;$ENDIF&#125;
&#123;$ENDIF&#125;
phxLogger;

&#123;$IFNDEF FPC&#125;
procedure CustomExceptions&#40;ExceptObject&#58; TObject; ExceptAddr&#58; Pointer&#41;; far;
var
Buffer&#58; array&#91;0..1023&#93; of Char;
begin
ExceptionErrorMessage&#40;ExceptObject, ExceptAddr, Buffer, SizeOf&#40;Buffer&#41;&#41;;
&#123;$IFDEF WINDOWS&#125;
CharToOemA&#40;Buffer, Buffer&#41;; //Necessary ANSI Conversion
&#123;$ENDIF&#125;
with TPHXLogger.getInstance do begin
Log&#40;logSevere, 'phxError', Buffer&#41;;
end;
Halt&#40;1&#41;;
end;
&#123;$ENDIF&#125;

begin
&#123;$IFNDEF FPC&#125;
ExceptProc &#58;= @CustomExceptions;
&#123;$ENDIF&#125;
MainLoop;
end.

Andreaz
10-08-2007, 06:13 PM
You need to regen the documentation though, since I noticed that the particle system has documentation but not in what is generated. ;)

I'm not using the documentation in the source for the doc generation anymore, it's just leftovers from before, the source gets to clustered with docs and tags to be really usefull. Im' writing it from scratch using the fpdoc tool instead, but it takes alot of time to complete through.

Thanks for the exception code, could prove helpfull :)

Robert Kosek
10-08-2007, 06:57 PM
I've glanced at FPC's error catching methodry but it seems more arcane and less friendly. We'll see though. Might be able to extract something useful for FPC users too.

Robert Kosek
10-08-2007, 08:17 PM
Hey Andreaz, if I want to make a particle system that I attach to ships (IE, an exhaust trail) that doesn't die except when their engines are off, what should I do? I set the duration to 0 and it doesn't die, but how should I go about making it so that the system peters out instead of continues to spawn particles? Should I just set duration to 0.00001? :)

Andreaz
11-08-2007, 08:31 AM
Hey Andreaz, if I want to make a particle system that I attach to ships (IE, an exhaust trail) that doesn't die except when their engines are off, what should I do? I set the duration to 0 and it doesn't die, but how should I go about making it so that the system peters out instead of continues to spawn particles? Should I just set duration to 0.00001? :)

As of now you have to change the effect of the system to a effect with Quota=0 when you dont want any more particles to be spawned and then change back when you need new ones

XTRiZ
18-08-2007, 10:53 AM
This is my xx attempt to start making a game =), and i would like to see an example where a sprite collides with a background. I read that there is a tile engine in the pipe, is there anything usable in it yet for a simple Jump'n'Run ?

Diaboli
04-09-2007, 11:37 AM
sry if this has been asked before:
is it possible that there might be a TPHXDraw in the future? as the current TDXDraw? cuz I find it hard to make the UI for my map-editor and character-editor with the system as it is now (i would much rather just use normal forms for this. atleast for the map-editor)

Robert Kosek
04-09-2007, 11:43 AM
There is a TPHXCanvas, which is a little inefficient, but is very canvas-like.

Diaboli
04-09-2007, 04:23 PM
i meant like a component that you can put on a form. like the TDXDraw, wich can be placed on a form and scaled and whatnot.

Andreaz
05-09-2007, 05:34 AM
Yeah there's one of thoose, but it's in the editor source bundle that i havn't released yet. I'll upload a zip with em (however they are in the state of working, and that's it)

http://phoenixlib.net/files/Util.zip

Diaboli
05-09-2007, 01:51 PM
thx! :D now i just have to find out how to use it... :P

EDIT: wich i just did... :P

Bones
14-09-2007, 03:41 PM
Hi ..
I just wanted to say thanks for this library.

Its simple, powerfull and chock-full of usefull and easy to use functionality that takes the grind out of delphi 2D games developing but leaves the fun bits in.
When I discovered how easy to use everything was and saw how professional the resource management tools were, I just decided I had to express my support and admiration.

I can't tell you how happy I am that I found this and really hope sincerely that you will keep up the great work.

I will soon be moving my IK+ online project over to phoenix from Delphix

Diaboli
16-09-2007, 02:02 PM
Hmm... does the TAnimatedSprite's Z property do anything?

In my game, a character is a set of different sprites put together. to get this working in UndelphiX, all i had to do, was to adjust the sprites Z-property so that a character standing behind another actually WAS behind it. this does somehow not work in Phoenix2D.

Mind explaining how Z-Buffering works here?

Example:
Body1:= TBody.Create(...);
Body2:= TBody.Create(...);
Body1.Z:= 0;
Body2.Z:= 1;
Body 2 is in front
then i tried
Body1.Z:= 1;
Body2.Z:= 0;
Body2 is still in front.

What is more is that i have to have different parts of a character on different layers, because one layer only takes one image (one layer for bodies, one for suits, one for hair, etc). this also ****s stuff up when to characters walk through eachother, and hair is ALLWAYS printed on top of bodies, unrelative to anything.

This on top of the Z-Buffering problem is giving me a headache.

Why not let EACH sprite have the ability to have its own image? I tried implementing that myself, but couldnt figure out how rendering and such works with openGL, so i gave up...

Pls Help?

Besides this, the engine is brilliant

Andreaz
16-09-2007, 02:58 PM
Well the z-buffering should work by default (unless it's disabled somewhere else) try calling


glEnable &#40;GL_DEAPTH_TEST&#41;;

before rendering the sprites and test if it helps. One thing to note thought, the blending might cause problems if you enable deapth testing, a sprite that is rendered before another sprite cant blend with the following one (this is a limitation of OpenGL and DirectX and has nothing to do with Phoenix). If you only has one color transparency you can avoid this by calling



glAphaFunct&#40;GL_GREATER, 0.1&#41;;
glEnable&#40;GL_ALPHA_TEST&#41;;


and this will skip all transparent pixels further up in the opengl pipeline.

The reason behind the sprite layers (wich was a new adition to the 1.0 release, the betas had one texture per sprite) is simply a speed matter, you can render 10x times the sprites by batching sprites into a larger spriteset instead of needing to rebind the texture for each sprite.

And for a hint on how to render one image per sprite:



//------------------------------------------------------------------------------
procedure TMyAnimatedSprite.Render;
var Image&#58; TPHXImage; // Move to private decleration
begin
Image&#58;= ImageList.Find&#40;'MyImage'&#41;; // move to constructor

glPushAtrib&#40;GL_TEXTURE_BIT&#41;; // Save the binded texture
Image.Bind;

glPushMatrix&#40;&#41;;
glTranslatef&#40;WorldPosition.X, WorldPosition.Y, WorldPosition.Z&#41;;

glCallList&#40;Image.DisplayList + PatternIndex + 1&#41;;
glPopMatrix&#40;&#41;;

glPopAttrib&#40;&#41;;
end;

Diaboli
03-10-2007, 08:34 PM
found this "bug":

procedure TPHXAnimation.Update(State: PPHXAnimationState; FrameTime: Single);
var Frame: TPHXAnimationFrame;
begin
// Only update if active
if( State^.Active) then begin
// Add the time to the state
State^.Time := State^.Time + FrameTime;

// Get the current frame
Frame:=FFrames[State^.Index];

// test if we shall change to the next frame
if( State^.Time > Frame.Time ) then begin
Inc(State^.Index);

// Test if we reached the end of the animation
if( State^.Index = Count) then begin //What if state is larger than count?


I found the problem when my sprites suddenly stopped worked when changing animation length from 4 to 1. wich would effectively make "State^.Index" larger than "Count".

the solution is obvious...

(and i have just spent an hour and a half trying to figure out what made my sprites disappear when i stopped moving)

Andreaz
09-10-2007, 03:08 AM
Hehe, yeah that was quite dumb tbh, in normal circumstances it would never occur (ie calling reset after editing the animation) but well.

BigJoe
03-02-2008, 09:35 PM
Hi

Have any information from next version?

Thx
BigJoe