XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

Strange thigs with SetData GetData :/

Last post 10/9/2008 11:18 PM by Spencer A. 2 replies.
  • 10/8/2008 1:49 PM

    Strange thigs with SetData GetData :/

    Hi.

    Well what I want to do is create smaller texture from part of another texture.

    Basicly I have one big texture 1024x1024 as level sprite sheet then I create sprites objects using "source rectangles" it would be almost ok but.. But if I want that sprire render with some texture velocity (f.e sky, waterfall) then sprite image area is limited not to source rectangle bounds but to sheet's area bounds. So this is why I am trying create smaller textures from big sheet texture for each object.

    Here's how it looks:

    Free Image Hosting at www.ImageShack.us

    Ok heres the code how I am coping part of sheet data and createing smaller texture

                    Color[ pixels = new Color[pSourceRect.Width * pSourceRect.Height];  
     
                    Texture2D temp_texture = Globals.Content.Load<Texture2D>(pAssetName);  
                    temp_texture.GetData<Color>(0, pSourceRect, pixels, 0, pSourceRect.Width * pSourceRect.Height);  
                    Texture = new Texture2D(Globals.Graphics.GraphicsDevice, pSourceRect.Width, pSourceRect.Height, 1, TextureUsage.None, SurfaceFormat.Color);  
                    Texture.SetData<Color>(pixels); 

    And here's that strange thing

    Free Image Hosting at www.ImageShack.us

    as You can see some part of the "bottom" data apears at the top :(

    So why is that so, what I am doing wrong?

     

    Thanks in anticipation

  • 10/8/2008 6:44 PM In reply to

    Re: Strange thigs with SetData GetData :/

    Are you sure that the pSourceRect is correct? If it is, it could be a bug in GetData<>(). You could try calling GetData<>() on all the data, and then pick out the pixels you want yourself using nested for() loops.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 10/9/2008 11:18 PM In reply to

    Re: Strange thigs with SetData GetData :/


    Texture2D newTexture = new Texture2D( 
        GraphicsDevice, srcRect.Width, srcRect.Height, 
        1, TextureUsage.None, SurfaceFormat.Color); 
    Color[ cData = new Color[srcRect.Width * srcRect.Height]; 
    oldTexture.GetData<Color>(0, srcRect, cData, 0, cData.Length); 
    newTexture.SetData<Color>(cData); 

     This is what I usually use in your situation, try and cross-referrence to find your problem.

    "At least we killed some boredom..."
Page 1 of 1 (3 items) Previous Next