[Aportes indexados] LoadSurface (DirectDraw)

Estado
Cerrado para nuevas respuestas.

Amraphen

Aprendiz Lvl 6
[VB6] LoadSurface (DirectDraw)

Buenas, acá les dejo un sub que hize para mi juego en desarrollo que simplemente carga una sección de un bitmap (ideal para cuando se tienene por ejemplo varios pisos dentro de un solo archivo). Este es el sub:

[vb]<div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="" class="li1"> </li><li style="" class="li1"><span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Sub</span> LoadSurface<span style="color: #66cc66;">(</span>ByRef Surface <span style="color: #b1b100;">As</span> DirectDrawSurface7, ByVal Path <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span>, ByVal X <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span>, ByVal Y <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span>, ByVal <span style="color: #b1b100;">Width</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span>, ByVal Height <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span><span style="color: #66cc66;">)</span></li><li style="" class="li2"><span style="color: #b1b100;">Dim</span> ddsdSurface <span style="color: #b1b100;">As</span> DDSURFACEDESC2</li><li style="" class="li1"><span style="color: #b1b100;">Dim</span> ddsdSurface2 <span style="color: #b1b100;">As</span> DDSURFACEDESC2</li><li style="" class="li1"><span style="color: #b1b100;">Dim</span> tmpSurface <span style="color: #b1b100;">As</span> DirectDrawSurface7</li><li style="" class="li2"><span style="color: #b1b100;">Dim</span> rec <span style="color: #b1b100;">As</span> RECT</li><li style="" class="li1"><span style="color: #b1b100;">Dim</span> rec2 <span style="color: #b1b100;">As</span> RECT</li><li style="" class="li1"> </li><li style="" class="li2">    ddsdSurface.<span style="color: #66cc66;">lFlags</span> = DDSD_CAPS <span style="color: #b1b100;">Or</span> DDSD_HEIGHT <span style="color: #b1b100;">Or</span> DDSD_WIDTH</li><li style="" class="li1">    ddsdSurface.<span style="color: #66cc66;">ddsCaps</span>.<span style="color: #66cc66;">lCaps</span> = DDSCAPS_OFFSCREENPLAIN</li><li style="" class="li1">    </li><li style="" class="li2">    <span style="color: #b1b100;">Set</span> tmpSurface = dd.<span style="color: #66cc66;">CreateSurfaceFromFile</span><span style="color: #66cc66;">(</span>Path, ddsdSurface<span style="color: #66cc66;">)</span></li><li style="" class="li1">    </li><li style="" class="li1">    ddsdSurface2.<span style="color: #66cc66;">lFlags</span> = ddsdSurface.<span style="color: #66cc66;">lFlags</span></li><li style="" class="li2">    ddsdSurface2.<span style="color: #66cc66;">ddsCaps</span>.<span style="color: #66cc66;">lCaps</span> = ddsdSurface.<span style="color: #66cc66;">ddsCaps</span>.<span style="color: #66cc66;">lCaps</span></li><li style="" class="li1">    ddsdSurface2.<span style="color: #66cc66;">lWidth</span> = <span style="color: #b1b100;">Width</span></li><li style="" class="li1">    ddsdSurface2.<span style="color: #66cc66;">lHeight</span> = Height</li><li style="" class="li2">    </li><li style="" class="li1">    <span style="color: #b1b100;">Set</span> Surface = dd.<span style="color: #66cc66;">CreateSurface</span><span style="color: #66cc66;">(</span>ddsdSurface2<span style="color: #66cc66;">)</span></li><li style="" class="li1">    </li><li style="" class="li2">    <span style="color: #b1b100;">With</span> rec</li><li style="" class="li1">        .<span style="color: #b1b100;">Left</span> = X</li><li style="" class="li1">        .<span style="color: #66cc66;">Top</span> = Y</li><li style="" class="li2">        .<span style="color: #b1b100;">Right</span> = X + <span style="color: #b1b100;">Width</span></li><li style="" class="li1">        .<span style="color: #66cc66;">Bottom</span> = Y + Height</li><li style="" class="li1">    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">With</span></li><li style="" class="li2"> </li><li style="" class="li1">    <span style="color: #b1b100;">With</span> rec2</li><li style="" class="li1">        .<span style="color: #b1b100;">Left</span> = <span style="color: #cc66cc;">0</span></li><li style="" class="li2">        .<span style="color: #66cc66;">Top</span> = <span style="color: #cc66cc;">0</span></li><li style="" class="li1">        .<span style="color: #b1b100;">Right</span> = <span style="color: #b1b100;">Width</span></li><li style="" class="li1">        .<span style="color: #66cc66;">Bottom</span> = Height</li><li style="" class="li2">    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">With</span></li><li style="" class="li1">    </li><li style="" class="li1">    <span style="color: #b1b100;">Call</span> Surface.<span style="color: #66cc66;">Blt</span><span style="color: #66cc66;">(</span>rec2, tmpSurface, rec, DDBLT_WAIT<span style="color: #66cc66;">)</span></li><li style="" class="li2"><span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Sub</span></li><li style="" class="li1"> </li></ol></div>[/vb]

O si quieren, el sub hecho función (que es más fácil para mi):

[vb]<div class="vb" id="{CB}" style="font-family: monospace;"><ol><li style="" class="li1"> </li><li style="" class="li1"><span style="color: #b1b100;">Private</span> <span style="color: #b1b100;">Function</span> LoadSurface<span style="color: #66cc66;">(</span>ByVal Path <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">String</span>, ByVal X <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span>, ByVal Y <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span>, ByVal <span style="color: #b1b100;">Width</span> <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span>, ByVal Height <span style="color: #b1b100;">As</span> <span style="color: #b1b100;">Long</span><span style="color: #66cc66;">)</span> <span style="color: #b1b100;">As</span> DirectDrawSurface7</li><li style="" class="li2"><span style="color: #b1b100;">Dim</span> ddsdSurface <span style="color: #b1b100;">As</span> DDSURFACEDESC2</li><li style="" class="li1"><span style="color: #b1b100;">Dim</span> ddsdSurface2 <span style="color: #b1b100;">As</span> DDSURFACEDESC2</li><li style="" class="li1"><span style="color: #b1b100;">Dim</span> tmpSurface <span style="color: #b1b100;">As</span> DirectDrawSurface7</li><li style="" class="li2"><span style="color: #b1b100;">Dim</span> rec <span style="color: #b1b100;">As</span> RECT</li><li style="" class="li1"><span style="color: #b1b100;">Dim</span> rec2 <span style="color: #b1b100;">As</span> RECT</li><li style="" class="li1"> </li><li style="" class="li2">    ddsdSurface.<span style="color: #66cc66;">lFlags</span> = DDSD_CAPS <span style="color: #b1b100;">Or</span> DDSD_HEIGHT <span style="color: #b1b100;">Or</span> DDSD_WIDTH</li><li style="" class="li1">    ddsdSurface.<span style="color: #66cc66;">ddsCaps</span>.<span style="color: #66cc66;">lCaps</span> = DDSCAPS_OFFSCREENPLAIN</li><li style="" class="li1">    </li><li style="" class="li2">    <span style="color: #b1b100;">Set</span> tmpSurface = dd.<span style="color: #66cc66;">CreateSurfaceFromFile</span><span style="color: #66cc66;">(</span>Path, ddsdSurface<span style="color: #66cc66;">)</span></li><li style="" class="li1">    </li><li style="" class="li1">    ddsdSurface2.<span style="color: #66cc66;">lFlags</span> = ddsdSurface.<span style="color: #66cc66;">lFlags</span></li><li style="" class="li2">    ddsdSurface2.<span style="color: #66cc66;">ddsCaps</span>.<span style="color: #66cc66;">lCaps</span> = ddsdSurface.<span style="color: #66cc66;">ddsCaps</span>.<span style="color: #66cc66;">lCaps</span></li><li style="" class="li1">    ddsdSurface2.<span style="color: #66cc66;">lWidth</span> = <span style="color: #b1b100;">Width</span></li><li style="" class="li1">    ddsdSurface2.<span style="color: #66cc66;">lHeight</span> = Height</li><li style="" class="li2">    </li><li style="" class="li1">    <span style="color: #b1b100;">Set</span> LoadSurface = dd.<span style="color: #66cc66;">CreateSurface</span><span style="color: #66cc66;">(</span>ddsdSurface2<span style="color: #66cc66;">)</span></li><li style="" class="li1">    </li><li style="" class="li2">    <span style="color: #b1b100;">With</span> rec</li><li style="" class="li1">        .<span style="color: #b1b100;">Left</span> = X</li><li style="" class="li1">        .<span style="color: #66cc66;">Top</span> = Y</li><li style="" class="li2">        .<span style="color: #b1b100;">Right</span> = X + <span style="color: #b1b100;">Width</span></li><li style="" class="li1">        .<span style="color: #66cc66;">Bottom</span> = Y + Height</li><li style="" class="li1">    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">With</span></li><li style="" class="li2"> </li><li style="" class="li1">    <span style="color: #b1b100;">With</span> rec2</li><li style="" class="li1">        .<span style="color: #b1b100;">Left</span> = <span style="color: #cc66cc;">0</span></li><li style="" class="li2">        .<span style="color: #66cc66;">Top</span> = <span style="color: #cc66cc;">0</span></li><li style="" class="li1">        .<span style="color: #b1b100;">Right</span> = <span style="color: #b1b100;">Width</span></li><li style="" class="li1">        .<span style="color: #66cc66;">Bottom</span> = Height</li><li style="" class="li2">    <span style="color: #b1b100;">End</span> <span style="color: #b1b100;">With</span></li><li style="" class="li1">    </li><li style="" class="li1">    <span style="color: #b1b100;">Call</span> LoadSurface.<span style="color: #66cc66;">Blt</span><span style="color: #66cc66;">(</span>rec2, tmpSurface, rec, DDBLT_WAIT<span style="color: #66cc66;">)</span></li><li style="" class="li2"><span style="color: #b1b100;">End</span> <span style="color: #b1b100;">Function</span></li><li style="" class="li1"> </li></ol></div>[/vb]

Básicamente lo que hace es cargar el bitmap en una superficie y luego se recorta la parte deseada, y se la devuelve.

Cualquier duda, pregunten! ^^
 
Estado
Cerrado para nuevas respuestas.
Arriba