Results 1 to 3 of 3

Thread: How to dynamically create sprites

  1. #1
    Join Date
    Mar 2008

    Default How to dynamically create sprites

    I am in the process of creating a rougelike game. For those that have no idea what rougelike is, it is old style rpg games that use letters and symbols like *, |, and ~ to represent the characters, terrain, and buildings in the game. Think ASCII Art.

    I've been looking at ClanLib since it has a very strong 2d slant and since it uses OpenGL by default, will run faster than SDL. I have run into the following issue: instead of creating hundreds of little image files, I was hoping to create the sprites dynamically and cache them to file. I've figured out that the following steps will be needed to create the sprite/s:

    1. Create some form of canvas or buffer
    2. Draw it's background as such-and-such color.
    3. Render letter/symbol onto canvas with such-and-such color
    4. Convert canvas into sprite.

    I know it will end with a CL_Sprite, but the classes before that I am not so sure of. I think it will involve CL_SpriteDescription and CL_Pixelbuffer as well, but I am not so sure. I would appreciate it if someone could point me in the right direction. Thanks in advance!

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002


    Sounds like a cool project.

    I do some sort of similar tricks when I generate thumbnails. I don't know if this is the best way, but here is how I do it:

    If you make a CL_Canvas, you can draw/render anything to it.

    I make one like this:
    m_pBackground = new CL_Surface(CL_PixelBuffer(x, y,x*4, CL_PixelFormat::abgr8888));
    m_pBackgroundCanvas = new CL_Canvas(*m_pBackground);
    Can draw lines:
    m_pBackgroundCanvas->get_gc()->draw_line(0, 0, 100, 100, CL_Color::yellow);
    Or text:
    pMyFont->draw(0,0, "Hello world!", m_pBackgroundCanvas->get_gc());
    When done, grab the part of the screen you want as a pixel buffer with m_pBackgroundCanvas->get_pixeldata(const CL_Rect &area).

    You can use the pixel buffer to create surfaces or sprites or save out the data if you wanted to cache it to disk.
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Join Date
    Mar 2008


    I played with the code you gave and it looks like it's exactly what I need. Your help is much appreciated!

Similar Threads

  1. how to create a window with picture background
    By gison in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 06-05-2007, 01:34 AM
  2. Dynamically generate GUI buttons,labels and stuff
    By d_oilen in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 11-22-2006, 09:21 AM
  3. I want to create my own dink game-help!!!
    By manicman in forum Dink Smallwood HD
    Replies: 5
    Last Post: 09-04-2006, 01:44 AM
  4. sprites
    By seyah3 in forum Dink Smallwood HD
    Replies: 0
    Last Post: 02-03-2006, 03:05 AM
  5. Replies: 2
    Last Post: 11-14-2005, 07:53 PM



Posting Permissions

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