DirectX9中是否有特定功能允许您指定LPD3DXSPRITE对精灵进行blits的位置?我正在尝试使用磁贴信息加载曲面,然后将该曲面的一部分显示给后缓冲区。我意识到使用LPD3DXSPRITE :: Draw()表示目标表面没有参数,它可能会自动成为后备缓冲区。然后我绘制的游戏世界表面覆盖了精灵。
是否有解决方案,或者我必须采用不同的方式来解决这个问题?我需要透明度,这就是为什么我想使用LPDIRECT3DTEXTURE9对象来处理我的瓷砖精灵,但地图将不适合后备缓冲,这就是为什么我想将地图加载到曲面上,然后从中绘制。< / p>
//Filename: MyDirectX.h
//Direct3D objects
extern LPDIRECT3D9 d3d;
extern LPDIRECT3DDEVICE9 d3ddev;
extern LPDIRECT3DSURFACE9 backbuffer;
extern LPD3DXSPRITE spriteobj;
LPDIRECT3DTEXTURE9 LoadTexture(string filename, D3DCOLOR transcolor = D3DCOLOR_XRGB(0,0,0));
void DrawTile(LPDIRECT3DTEXTURE9 source, int frame, int width, int height, int columns, LPDIRECT3DSURFACE9 dest, int destx, int desty, D3DCOLOR color);
void BuildGameWorld();
void ScrollScreen();
/////////////////////////////////////////////////////////////////////////////
//Filename: MyGame.cpp
#include "MyDirectX.h"
//THIS FUNCTION HERE
void DrawTile(LPDIRECT3DTEXTURE9 source, int frame, int width, int height, int columns, LPDIRECT3DSURFACE9 dest, int destx, int desty, D3DCOLOR color)
{
//get dimensions for the tile
RECT r1;
r1.left = (frame % columns) * width;
r1.top = (frame / columns) * height;
r1.right = r1.left + width;
r1.bottom = r1.top + height;
//can only draw to the backbuffer? Any work around?
spriteobj->Draw(source, &r1, &D3DXVECTOR3(r1.right / 2, r1.bottom / 2, 0), &D3DXVECTOR3(destx, desty, 0), color);
}
void BuildGameWorld()
{
int x, y;
LPDIRECT3DTEXTURE9 tiles = nullptr;
//load the texture file
tiles = LoadTexture("goodly-2x.png", D3DCOLOR_XRGB(255, 0, 255));
spriteobj->Begin(D3DXSPRITE_ALPHABLEND);
for(y = 0; y < MAPHEIGHT; y++)
{
for(x = 0; x < MAPWIDTH; x++)
{
DrawTile(tiles, MAP_LAYER1[y * MAPWIDTH + x], 32, 32, 16, gameworld, x * 32, y * 32, D3DCOLOR_XRGB(255,255,255));
}
}
spriteobj->End();
//release the texture file
tiles->Release();
}
//Without this function, and placing BuildGameWorld() inside the Game_Run()
//rendering phase the screen displays stripes of blue which I can only
//assume is the transparent tiles working incorrectly*/
void ScrollScreen()
{
//update horizontal scrolling position and speed
ScrollX += SpeedX;
if (ScrollX < 0)
{
ScrollX = 0;
SpeedX = 0;
}
else if (ScrollX > GAMEWORLDWIDTH - SCREENW)
{
ScrollX = GAMEWORLDWIDTH - SCREENW;
SpeedX = 0;
}
//update vertical scrolling position and speed
ScrollY += SpeedY;
if (ScrollY < 0)
{
ScrollY = 0;
SpeedY = 0;
}
else if (ScrollY > GAMEWORLDHEIGHT - SCREENH)
{
ScrollY = GAMEWORLDHEIGHT - SCREENH;
SpeedY = 0;
}
//set dimensions of the source image
RECT r1 = {ScrollX, ScrollY, ScrollX+SCREENW-1,
ScrollY+SCREENH-1};
//set the destination rect
RECT r2 = {0, 0, SCREENW-1, SCREENH-1};
d3ddev->StretchRect(gameworld, &r1, backbuffer, &r2,
D3DTEXF_NONE);
}
答案 0 :(得分:1)
由于您使用的是ID3DXSprite,因此指定渲染目标的最简单方法是使用ID3DXRenderToSurface,如下所示:
if(i == jcontent.size()){ //here i == 10
.......
.......
viewHolder.pages.setText(Integer.toString(jcontent.get(i).pages));
//here you are accessing the 10 element of jcontent.
}