Is there a faster alternative to using textures in XNA?

I am writing a map editing program for a 2D game using XNA. To create Texture2D for all the fragments required by the map, it takes too much time.

Are there any alternatives to using textures to paint with XNA?

I tried to create only one texture for the tile set instead of the texture for each tile in the tile set, but there is a limit on the size of the textures, and I could not put all the tiles in the tile set into one texture.

Currently, the program contains all potential textures in memory as Bitmap objects. Is there a way to just draw a Bitmap object on screen in XNA? I searched, but I can not find any information about this. This approach will not allow you to create textures at all, but any shades or effects that I will have to do with the bitmap directly.

+5
source share
7 answers

, , XNA; , Texture, . , , , ( , 1024 4096 ...) - ? lazy-load , , - , - , , .

, - XNA? , , WPF, BitmapSources .

0

, ( ), XNA (http://msdn.microsoft.com/en-us/library/bb447754.aspx), , .

, , ++, DirectX. Visual ++ Windows Forms, Visual Studio.

+1

, , x y ?

# :

myGraphicsDevice.Textures[0] = whateverYourGiantMapTextureIs;

foreach(MapChunk chunk in mapChunks) {
    myShader.Effect.Parameters["xOffset"] = chunk.XOffset;
    myShader.Effect.Parameters["yOffset"] = chunk.YOffset;

    myGraphicsDevice.DrawIndexedPrimitives( your chunk drawing code here );
}

:

float4x4 World; 
float4x4 View; 
float4x4 Projection;

float xOffset;
float yOffset;

sampler TextureSampler; 

struct VS_INPUT { 
    float4 Position : POSITION0; 
    float4 Color    : COLOR0;
};

VS_INPUT Transform(VS_INPUT Input) { 
    VS_INPUT Output; 

    float4 worldPosition = mul(Input.Position, World); 
    float4 viewPosition = mul(worldPosition, View); 
    Output.Position = mul(viewPosition, Projection); 
    Output.Color = Input.Color;

    return Output; 
} 

float4 ColorTexture(VS_INPUT Input) : COLOR0{ 
    return Input.Color.rgba * tex2D(TextureSampler, float2(xOffset, yOffset));
} 

technique TransformColorTexture { 
    pass P0 { 
        VertexShader = compile vs_2_0 Transform(); 
        PixelShader = compile ps_2_0 ColorTexture(); 
    } 
}

, .

+1

. , , ( - ).

- - ( ..), tilemaps . , :

1: (, 40 32 * 32 )

2: tilemap:   40 - 6.-, 7. 7 * 32 - 224, , 256 , 256x256. ( , )

3: Rendertarget2D, .

4: rendertarget.

5: rendertarget:

int x, y = 0;
foreach (var tile in allTiles)
{
    RenderTile(tile, x*32, y*32);
    x++;

    if (x >= 8)
    {
        x = 0;
        y++;
    }
}

betch-render 4 * 40 . 4 , , (0,1,2 ..). [40] , tileIndex (int [40]) , tilemap.

, : s

, , (640x360), , 5 + , , ( ..), , ...

+1

, , , , , ? ?

, . , , ? XNA xnb, , .

, , ( , - ), , .

0

, , .

, /, .

0

, ?

. Threading # XNA.

, , ( ) . , , ( , Draw()!!), , .

0

All Articles