Results 1 to 8 of 8

Thread: cl_sprite with multiple frames

  1. #1
    Peasant
    Join Date
    Oct 2007
    Posts
    6

    Default cl_sprite with multiple frames

    I've noticed that any sprite.get_frame_surface(index) doesn't return jsut that frame but the entire sprite. Same goes with get_frame_pixeldata(index), I get the whole sprite and not just one specific frame.

    The sprite is working correctly as the animation works by using either update() or drawing individual frames with set_frame(index) and draw().

    Is this a known bug or am I doing something wrong?

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    Hmm, I think these are fixed on the 0.8 SVN version. Have you tried that?
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Peasant
    Join Date
    Oct 2007
    Posts
    6

    Default

    I am using 0.8, is there a different 0.8 svn version? I just assumed that all 0.8 would be synced. Anyway I'm compiling 0.8 from svn now and will test once it's done. Thanks for pointing that out

  4. #4
    Peasant
    Join Date
    Oct 2007
    Posts
    6

    Default

    Got 0.8 svn up and running now, but get_frame_surface() still gives me the entire sprite and not just the specified frame...

    If it matters, I'm doing this on a linux gentoo x86_64 box.

    And I also tested using both SDL and opengl drawing backends.

    This is the code I use, reason it has it's own function is because I've tried numerous different methods to accomplish this, but ideally this piece of code should work no?

    Code:
    CL_Surface NinjaApp::SpriteFrameToSurface(CL_Sprite sprite, int frame)
    {
        CL_Surface sf = sprite.get_frame_surface(frame);
        return sf;
    }

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

    Default

    No, that function is returning the surface which the sprite is using. Since we pack as many sprites frames as we can into one surface to help performance, there is not easy way to create a Surface from a Sprite frame. Perhaps it could work using a Pixelbuffer (which you copy a region from the surface and then create a surface from a pixelbuffer).

    Why do you want to do this btw? Seems a bit weird

  6. #6
    Peasant
    Join Date
    Oct 2007
    Posts
    6

    Default

    Haha I guess it is. And indeed I've managed to get what I wanted without doing that apparantly bothersome procedure.

    The reason I wanted to do it is because I have a .tga file with a bunch of 32x32 tiles and since some tiles have multiple images (for example a tile with a candle, moving flames you know ) I wanted to copy them to a separate CL_Sprite to let that class handle the animation.

    Anyway I have let animated tiles be for the moment, I should be able to get that working too with just a small addition.

    Would be nice to know if it is possible though, I'm sure I can find some use for it at a later stage And fyi, I've tried copying to a pixelbuffer and then using set_pixeldata() into a surface but that always gives a segfault. Maybe I need to set a proper pixelformat somehow?

    I guess this is solved for now, but if you have an idea of how to do the copy feel free to post. Thanks for the input!

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

    Default

    You can create a animated sprite from the surface in either resources, or using SpriteDescription. Then you could for instance use tile1 in Sprite1, tile2 in Sprite2, tile3-6 in Sprite3, etc

    Probably wrong syntax since its been a while since I used this, but something like:

    <sprite name="tile1"><image file="surface.png"><grid pos="0,0" size="32,32"/></image></sprite>
    <sprite name="tile2"><image file="surface.png"><grid pos="32,0" size="32,32"/></image></sprite>
    <sprite name="tile3"><image file="surface.png"><grid pos="64,0" size="32,32" array="3,1"/></image></sprite>

    Or in code:
    CL_PixelBuffer buf = CL_ImageProviderFactory::load("tiles.png");
    CL_SpriteDescription tiledesc1;
    tiledesc1.add_gridclipped_frames(buf, 0, 0, 32, 32, 1, 1, 0, 0, false);
    CL_SpriteDescription tiledesc2;
    tiledesc2.add_gridclipped_frames(buf, 32, 0, 32, 32, 1, 1, 0, 0, false);
    CL_SpriteDescription tiledesc3;
    tiledesc3.add_gridclipped_frames(buf, 64, 0, 32, 32, 3, 1, 0, 0, false);

    CL_Sprite tile1(tiledesc1);
    CL_Sprite tile2(tiledesc2);
    CL_Sprite tile3(tiledesc3);

  8. #8
    Peasant
    Join Date
    Aug 2008
    Posts
    6

    Default CL_PixelBuffer from XML

    Anybody can tell me how can I load CL_PixelBuffer image form resource XML file?

    My code now:
    Code:
    CL_PixelBuffer attack_model_buf = CL_ProviderFactory::load("Gfx/creatures/attack.png");
    
    CL_SpriteDescription attack_nn, attack_ee, attack_ss, attack_ww;
    attack_nn.add_gridclipped_frames(attack_model_buf, 0, 576, 96, 96, 9, 1, 0, 0, false);
    attack_ee.add_gridclipped_frames(attack_model_buf, 0,   0, 96, 96, 9, 1, 0, 0, false);
    .....

Similar Threads

  1. Setup networking in multiple threads?
    By catch22 in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 07-17-2007, 11:55 PM
  2. CL_Sprite problems
    By gmatt in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 06-29-2007, 05:38 PM
  3. Feature questions.. (visual profiles, minimap, multiple saves)
    By whisperstorm in forum Novashell Game Creation System
    Replies: 1
    Last Post: 01-06-2007, 10:53 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
  •