Game Development Community

Texture/Material Strip?

by Kabe R. · in Torque X 2D · 04/08/2007 (6:29 pm) · 8 replies

Hi, i'm new to TorqueX and i'm trying to understand the correct classes to use to do the following:

I have several png images that are strips of different images, such as i have one strip that contains the icons for all of my game powerups. I want to place sprites in my scene and set the material of the sprite to a specific icon within this image strip, for example if i want to use the 3rd icon which would be my health powerup, i want to clone the PowerUp SceneObject and somehow set its material to the 3rd segment of my strip.

Any pointers on how to do this would be great. I realize i could do this with an AnimiatedSprite, and just not have it animate but rather just pick which cell it should show, but i'm not sure if this is the best/correct way to do it, or if a Quad would be more accurate, etc. I could use some guidance here, thanks!

About the author

Recent Threads

  • iTGB HTTP?

  • #1
    04/09/2007 (7:15 am)
    Why do you have them as a 'strip' of images instead of having each thing it's own seperate image? I would splice the image and keep them all seperate.

    www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

    www.mmogamedev.info/images/imgdc_ad1.gif
    #2
    04/09/2007 (9:55 am)
    Actually Jonathon, texture strips/sheets can be extremely efficient when used properly--less state changes and all that, plus a variety of other optimizations.

    That being said, a quick and easy method is to define the material as a set of cells, and then create T2DStaticSprites that use it, and give each one a different frame to display. This isn't true texture sheeting in a sense, but it does accomplish what you are asking--it can however be a bit more difficult to read your code unless you set up an Enum that contains a mapping of your image names to their cells within the texture strip.
    #3
    04/09/2007 (11:12 am)
    Thanks Stephen,

    The enum idea is exactly where i'm going with this, as i can then just tell my new cloned object foo.setVisual( PowerUp.HEALTH ).

    However i'm looking at the API docs and i can't seem to figure out how to define a material in the way you describe. I got a T2DAnimationData setup last night to do something like this, but it seemed kinda hacky, and i really just want to deal with the texture/material itself.

    Any pointer as to what API call i should be making would be great, What material class should i be using? TextureMaterial?
    #4
    04/09/2007 (11:37 am)
    If it's for completely different objects and not a single object that simply switches materials at run-time, I don't see what the gain is in using a texture strip Stephen. I'm a nub to graphics programming, so enlighten me!
    #5
    04/09/2007 (2:07 pm)
    @John: I would, but I'm not an expert in the CPU --> GPU pipeline myself unfortunately.

    I just know that one of the recommended "final optimizations" for games, especially 2D, is to pack textures into texture sheets.

    One of the reasons my not directly apply, but an example would be that with certain texture sizes, and the power of 2 requirements video cards have, you can pack quite a bit of textures into "empty" space of large, unusually dimensioned single images.

    Picture a texture that for whatever reason has to be 1200x1200. This gets inflated into a 2048x2048 size texture before being sent to the video card, and therefore has a huge amount of empty space that could otherwise be placed up on the card's memory, saving you having to send all the smaller textures individually.

    Regarding the original poster's question: I just experimented in TGB-X, and it turns out something you can do in TGB cannot be done in the editor with TGB-X: make a static sprite with a multi-framed material. I'll bounce this question up and see if there is a way to do it via C#, but my original statement may turn out to be incorrect in the current engine iteration.
    #6
    04/12/2007 (1:55 am)
    Unfortunately, celled and keyed images aren't supported in 1.0. The code to do it is done, but it didn't make the cut in time, so it will be in a later release. The good news is that the "later" release will likely be fairly soon after 1.0. I actually just wrote a .plan about the new celled image stuff the other day (pics towards the bottom).

    In the meantime, you will have to separate your images. Sorry. :(
    #7
    04/12/2007 (6:40 am)
    Thanks for the response Thomas. No problem, i'll break out my image for now or cludge together an AnimatedSprite with a modified AnimationData (i have this working now, i just set the data to only show the one frame i want). I'm looking forward to the future release and i'm glad this is part of the roadmap.

    Thanks!
    #8
    04/12/2007 (7:45 am)
    Ideally you would just chop the images up. There's a tiny bit of overhead involved with animated sprites because they have to animate. If you go with animated sprites just make sure your animation data's aren't set to loop.