Results 1 to 3 of 3

Thread: Question about moving from CL_Surface to 2.1 classes

  1. #1
    Lesser Knight
    Join Date
    Jan 2010
    Posts
    52

    Default Question about moving from CL_Surface to 2.1 classes

    In my project, I used to use a CL_Surface loaded from a png image in my resources, and then blit one rectangle from that surface onto my display (the CL_Surface was a set of tiles, and I was blitting individual tiles).

    I understand that CL_Image replaces most of the functionality of CL_Surface, but it doesn't allow you to specify a source rectangle.

    Is CL_Sprite the new way to achieve this?

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Location
    Bergen, Norway
    Posts
    588

    Default

    You could probably use both. If you use CL_Sprite, you could define the tiles using resource files, and get an automatic system:

    int x = 53;
    int y = 23;

    CL_Sprite sprite("some resource", ...)
    sprite.set_frame(17); // Draw tile #17
    sprite.draw(gc, x, y);

    Using CL_Image, you'll need to do the "clipping" yourself:

    CL_Image image("...");
    CL_Rectf src(0,0,16,16); // Tile #1
    CL_Rectf dest(x+0,y+0,x+16,y+16);
    image.draw(gc, src, dest);

  3. #3
    Lesser Knight
    Join Date
    Jan 2010
    Posts
    52

    Smile

    Quote Originally Posted by sphair View Post
    You could probably use both. If you use CL_Sprite, you could define the tiles using resource files, and get an automatic system:

    int x = 53;
    int y = 23;

    CL_Sprite sprite("some resource", ...)
    sprite.set_frame(17); // Draw tile #17
    sprite.draw(gc, x, y);

    Using CL_Image, you'll need to do the "clipping" yourself:

    CL_Image image("...");
    CL_Rectf src(0,0,16,16); // Tile #1
    CL_Rectf dest(x+0,y+0,x+16,y+16);
    image.draw(gc, src, dest);
    Oh. Duh... for some reason I thought image didn't allow specifying a source rectangle, but I see now that it does! Heehee, thats exactly what I need, then. Thanks

Similar Threads

  1. Moving focus around
    By Harry in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 07-25-2009, 03:47 AM
  2. ClanLib 2.0 and CL_Surface
    By falsinfab in forum Official ClanLib SDK Forums
    Replies: 1
    Last Post: 05-16-2009, 04:45 PM
  3. Help Need, moving Dink
    By Arjayty in forum RTsoft Tavern
    Replies: 0
    Last Post: 11-05-2008, 11:35 AM
  4. Mask of CL_Surface
    By karaman in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 06-01-2008, 08:57 AM
  5. Race condition in network classes
    By Niklas in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 09-22-2006, 12:11 PM

Bookmarks

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
  •