Recent

Author Topic: [SLD2 UNIT] Drawing a piece of image  (Read 4420 times)

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
[SLD2 UNIT] Drawing a piece of image
« on: August 27, 2016, 04:48:53 pm »
Hello, A tip please. Working with SDL2 and images, for example: there is an image file ( only one) in which there are the textures of two cars( only an example). How i can i draw only one of these cars? I only know how to draw the full texture.. please help
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: [SLD2 UNIT] Drawing a piece of image
« Reply #1 on: August 27, 2016, 05:29:49 pm »
SDL_RenderCopy() (guess what the srcrect parameter does  ;) )

ps: as already suggested to you,, please read the SDL2 tutorials on fpc-meets-sdl.
« Last Edit: August 27, 2016, 05:40:55 pm by molly »

DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: [SLD2 UNIT] Drawing a piece of image
« Reply #2 on: August 27, 2016, 09:37:42 pm »
SDL_RenderCopy() (guess what the srcrect parameter does  ;) )

ps: as already suggested to you,, please read the SDL2 tutorials on fpc-meets-sdl.
I already guessed all the 10 chapters at the beginning but it doesn't show an example of that function ( srcrect).
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: [SLD2 UNIT] Drawing a piece of image
« Reply #3 on: August 27, 2016, 09:47:55 pm »
if you look at the code I posted http://forum.lazarus.freepascal.org/index.php/topic,33827.msg220127.html#msg220127
it solves both your questions. you should go to the Sdl2 page it has all the answers if you look hard enough
https://wiki.libsdl.org/FrontPage

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: [SLD2 UNIT] Drawing a piece of image
« Reply #4 on: August 27, 2016, 10:09:02 pm »
Quote
I already guessed all the 10 chapters at the beginning but it doesn't show an example of that function ( srcrect).
Indeed no example, but it is being discussed in the accompanied text.

It's pretty simple. You can give RenderCopy() both a source as well as a destination rectangle (another question you had in the thread linked by Carver413).

The srcrect parameter is the rectangle it needs to copy from your image. The rectangle is given in pixels, and i am assuming that you know where your first and your second car are located (pixel-wise) inside the image.

The example where Carver413 pointed to, shows how you can provide a rectangle. The only thing left for you to do is storing the correct x/y coordinates as well as correct width and height inside the rectangle and provide that to RenderCopy()'s srcrect parameter.


DiCri

  • Full Member
  • ***
  • Posts: 151
  • My goal : Build a game
    • http://manueldicriscito.altervista.org/DinoLand.zip
Re: [SLD2 UNIT] Drawing a piece of image
« Reply #5 on: August 28, 2016, 05:49:08 pm »
Quote
I already guessed all the 10 chapters at the beginning but it doesn't show an example of that function ( srcrect).
Indeed no example, but it is being discussed in the accompanied text.

It's pretty simple. You can give RenderCopy() both a source as well as a destination rectangle (another question you had in the thread linked by Carver413).

The srcrect parameter is the rectangle it needs to copy from your image. The rectangle is given in pixels, and i am assuming that you know where your first and your second car are located (pixel-wise) inside the image.

The example where Carver413 pointed to, shows how you can provide a rectangle. The only thing left for you to do is storing the correct x/y coordinates as well as correct width and height inside the rectangle and provide that to RenderCopy()'s srcrect parameter.
Ok got it and now it works!
I'm a game developer.. Now studying..
Go download my game:
http://manueldicriscito.altervista.org/DinoLand.zip

 

TinyPortal © 2005-2018