:? No ideia, i don't see anything wrong at this lineOriginally Posted by Loodziek
:? No ideia, i don't see anything wrong at this lineOriginally Posted by Loodziek
From brazil (:
Pascal pownz!
1.0 Beta I think. Just try compile this code in Delphi, then compile it in Lazarus:
[pascal]
program Test;
uses SDL;
var
surface : PSDL_Surface;
begin
SDL_SetColorKey(surface, SDL_RLEACCEL or SDL_SRCCOLORKEY, SDL_MapRGB(surface.format, 255, 0, 255));
end.
[/pascal]
Runtime error doesn't matter.
-Edit-
Ok, I read some sources and I find where be an error. Well it should be "surface^.format" not "surface.format". Now everything should works fine
Hi again. When I know basics of SDL it's time to try write something. But, at start I find a first problem. I wanna load map from file to dynamic table. So first I must do SetLength, right? I write a dwo functions to get X and Y. Here is my map file (data\maps\map1.txt):
There are two sprites. Map X is a spaces count in one line + 1, right? So there's my funciton:Code:1 1 1 2 1 1 1 1 1 2 2 2 2 2 2 2 2 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1 1 2 1
[pascal]
function GetMapX : integer;
var
count : integer;
StrChain : string;
MapFile : TextFile;
begin
AssignFile(MapFile, MapPath); //Map path is a global cons 'data\maps\map1.txt'
Reset(MapFile);
Read(MapFile, StrChain);
Result := 0;
for count := 0 to Length(StrChain) do
if StrChain[count] = ' ' then
Result := Result + 1;
Result := Result + 1;
CloseFile(MapFile);
end;
[/pascal]
I hope it's clear for u. This function is in "Maps.pas". And there's my project file. Everything works fine:
[pascal]
program SDL_proby;
{$mode objfpc}{$H+}
uses
SDL, SDL_Image, ImagesDraw, SDL_TTF, FontsDraw, Maps, Player;
const
//Wymiary okna
width = 900;
height = 900;
var
screen : PSDL_Surface;
grass : PSDL_Surface;
logo : PSDL_Surface;
road_horizontal : PSDL_Surface;
pos : TSDL_Rect;
i : integer;
loop : boolean;
procedure Init;
begin
SDL.SDL_Init(SDL_Init_Video);
screen := SDL_SetVideoMode(width, height, 32, SDL.SDL_SWSurface);
TTF_Init;
loop := true;
end;
procedure OnQuit;
begin
SDL.SDL_FreeSurface(grass);
SDL.SDL_FreeSurface(screen);
TTF_Quit;
SDL.SDL_Quit;
end;
procedure doGameInput;
var
KeyPress : TSDL_Event;
begin
while (SDL.SDL_PollEvent(@KeyPress) > 0) do
case (KeyPress.Type_) of SDL.SDL_Keydown :
if (KeyPress.Key.keysym.sym = SDL.SDLK_ESCAPE) then loop := false;
end;
end;
//*************************************************
//************ KOD G¬£?ìWNY PROGRAMU*****************
//*************************************************
begin
Init;
for i := 0 to 5 do ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\grass.jpg', i * 64, 0, 64, 64, screen);
for i := 0 to 5 do ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\road.jpg', i * 64, 128, 64, 64, screen);
ImagesDraw.DrawImage('C:\Documents and Settings\WINDOWS XP\Moje dokumenty\Moje obrazy\beczka.bmp', 0, 0, 64, 64, screen);
repeat
SDL.SDL_Delay(30);
doGameInput;
SDL.SDL_Flip(screen);
until loop = false;
OnQuit;
end.
[/pascal]
I know, I know there's a not used vars and it's not optimized yet. Anyway, it works. But when I put "mx : integer" to var and put "mx := GetMapX" to code it's compiling but I get only black screen. Why it don't work? When I compile my GetMapX function in Delphi and do:
[pascal]
mx := GetMapX;
ShowMessage(IntToStr(mx));
[/pascal]
Then I get 9 (it works). I'm trying, and tying but after some tryies I must restar coputer because something is wrong with exe file... So it's very bored And sorry for double posting - I just want to set topic into "New Posts" state.
Yeah you get the function working but you drawed the map ?
I use Tstringlist in my bitmapfont unit, but in your case i think its not suitable, i don't have sure but TTF are veryyy slow on asphyre {that is lot faster than SDL} compared to prerendered fonts so i would suggest you to use bitmap fonts instead.
About the exe problem i don't know :?
From brazil (:
Pascal pownz!
Yes, I don't draw map yet. I just want to check my function and prgram crashes. And I don't know why :/ What bitmapfonts and TTF have to mine problem? :think:
If you don't nothing the screen will be black,Originally Posted by Loodziek
*no its only a suggestion for better speed.
From brazil (:
Pascal pownz!
Arthur, look to my code again. There is a procedure "DrawImage" I draw 4 grass sprites, 4 road sprites and one barrel But when I just put my function to file program don't render anything and it cannot be closed (I must use Crtl + Alt + Delete). I found a line where's program crash:
[pascal] Read(MapFile, StrChain); [/pascal]
When I write ReadLn theres a the same problem. What do u think?
Make use of SDL_Blitsurface insted..Originally Posted by Loodziek
So it crashes while reading the file ?
From brazil (:
Pascal pownz!
My DrawImage is a IMG_Load, BlitSurface and others
And yes, program crashes when I try to read file. Is it possible to use TextFiles with JEDI-SDL?
Bookmarks