Page 3 of 3 FirstFirst 123
Results 21 to 30 of 31

Thread: Game Developement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Realeg View Post
    This is the code i just write to handle the files. The error i recive is that the path variable gets an AnsiString and the parameter for the IMG_LoadTexture is a pChar. How do i convert them?
    Wrap the code defining path into PChar method:

    Code:
        Tex[1]:=IMG_LoadTexture(PChar(Ren,path+'\monster.bmp'));

  2. #2
    Tried your solution, it dosen't work...

  3. #3
    Quote Originally Posted by Realeg View Post
    Code:
    program grafica;
    
    uses SysUtils,crt,SDL2,SDL2_image;
    
    type Textures=array[1..100] of pSDL_Texture;
    
    var Window:pSDL_Window; var Tex:Textures; Ren:pSDL_Renderer;
    
    procedure Graphic_Initialisation(var Window:pSDL_Window);
    begin
        if SDL_INIT(SDL_INIT_VIDEO)<0 then
            writeln('An error ocurred, the program will now quit')
        else
            begin
                writeln('Graphic mode succesfully initialisated');
                Window:=SDL_CreateWindow('Test',50,50,600,400,SDL_WINDOW_SHOWN);
            end;
    end;
    
    procedure Texture_Loading;
    var path:pChar;
    begin
        Ren:=SDL_CreateRenderer(window,-1,0);
        path:=ExtractFilePath('grafica.exe');
        Tex[1]:=IMG_LoadTexture(Ren,path+'\monster.bmp');
        Tex[2]:=IMG_LoadTexture(Ren,path+'\monster1.bmp');;
    end;
    
    procedure Graphic_Composer;
    var i:byte;
    begin
        Texture_Loading;
        for i:=1 to 100 do
            begin
                if (i mod 2)=1 then
                    begin
                        SDL_RenderCopy(Ren,Tex[1],nil,nil);
                        SDL_RenderPresent(Ren);
                        SDL_DELAY(50);
                    end
                else
                    begin
                        SDL_RenderCopy(Ren,Tex[2],nil,nil);
                        SDL_RenderPresent(Ren);
                        SDL_Delay(50);
                    end;
            end;
    end;
    
    procedure Graphic_Destroy;
    var i:byte;
    begin
        for i:=1 to 100 do    
            SDL_DestroyTexture(Tex[i]);
        SDL_DestroyRenderer(Ren);
        SDL_DestroyWindow(Window);
        SDL_QUIT;
    end;
    
    begin
        clrscr;
        Graphic_Initialisation(Window);
        Graphic_Composer;
        Graphic_Destroy;
    end.
    I think you must validate that ExtractFilePath didn't gets you a string path with '\' at the end. That could produce unexpected results as you are having.

  4. #4
    Am i doing it wrong or... i tried to use what you told me below and got this
    Code:
     path:=pChar(ExtractFilePath(grafica.exeName));
    I know it's wrong, but with what should i replace that to make it work?

  5. #5
    Ahh now I see what is confusing you.

    When I write use Application.ExeName I mean that literally.

    You see in modern pascal dialects the Application is actually a global variable for TApplication class which contains several properties and methods. Best example of seeing this in use is looking ath the source of your project file (*.dpr file).

    And one of its properties is ExeName which contains full filename of your application executable.

  6. #6
    With Freepascal you can also use the "old school" way:
    Code:
    path:=ExtractFilePath(ParamStr(0));
    (No need for pChar as you can see.)
    Best regards,
    Cybermonkey

  7. #7
    Quote Originally Posted by Realeg View Post
    I wonder, how could i make games in Turbo Pascal using graphics? I tried to use the "graph unit" integrated with pascal, but i can't use the keyboard in the graphic window.
    So, i'm here to ask you, what i need to start create a graphic game using Pascal language?
    I would recommend installing Lazarus for that kind of stuff. Turbo pascal is only for learning basics, starting to use graphics on it won't lead anywhere, and gives you too much information you don't need. No modern time games can be made with Turbo Pascal.

  8. #8
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    What Silverwarrior suggested :

    Tex[1]:=IMG_LoadTexture(PChar(Ren,path+'\monster.bmp'));

    should read :

    Tex[1]:=IMG_LoadTexture(Ren,PChar(path+'\monster.bmp'));
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  9. #9
    Quote Originally Posted by phibermon View Post
    What Silverwarrior suggested :

    Tex[1]:=IMG_LoadTexture(PChar(Ren,path+'\monster.bmp'));

    should read :

    Tex[1]:=IMG_LoadTexture(Ren,PChar(path+'\monster.bmp'));
    You are absolutely correct. How could I have made such trivial mistake

  10. #10
    Ok, in the end i mananged to find out how to make it work with paths, thanks to both of you
    Another question: I've heard from my teacher that in the Pascal IDE are some options or something like that to show the amount of memory and time execution of a program. Can you tell me how to make use of them?

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •