ivan's blog

ivan's blog

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks

常用链接

留言簿

我参与的团队

搜索

  •  

最新评论

很感谢你的教程,如果让我自己摸索,估计很难找到正确的方法~~
我想问的是,好象即使改变字体文件,显示的文字也不会改变字体。
如果想改变显示文字的字体应该如何做?
具体实现是:
std::string int_to_string(int num)
{
std::ostringstream ss;
ss << num;
return ss.str();
}
如果这样写
for ( int i = 0; i < 4; i++ ) {
screen.fillColor(0xFF, 0xFF, 0xFF);
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);
}

就变成只有一个球了,也不太理解为什么会这样。。。
非常感谢你的回答,我试了下,结果是这样才正常
//clip dots.
for ( int i = 0; i < 4; i++ )
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);

//Draw dots and screen.
screen.flip();
screen.fillColor(0xFF, 0xFF, 0xFF);
做点小改动,结果小球运动的时候出现难看的“轨迹”
不知道如何修改才能正常
int game(int argc ,char* argv[])
{
//Create a SDL screen.
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT);
//Fill background with white.(default is black)
screen.fillColor(0xFF, 0xFF, 0xFF);

//Load a sprite pic, and colorkey.(default color: R=0,G=0xFF,B=0xFF)
DisplaySurface sprite("dots.png", screen);
sprite.colorKey();

//the 4 dots's coordinate.
int atX[4] = {0, 590, 0, 590};
int atY[4] = {0, 0, 430, 430};
//the 4 dots's clip coordinate.
int fromX[4] = {0, 270, 0 ,270};
int fromY[4] = {0, 0, 190, 190};
//mouse's coordinate.
int px = 0;
int py = 0;
//dots's size.
const int IMG_WIDTH = 50;
const int IMG_HEIGHT = 50;
//clip dots.
for ( int i = 0; i < 4; i++ )
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT);
//Draw dots and screen.
screen.flip();

//press ESC or click X to quit.
bool gameOver = false;
SDL_Event gameEvent;
while( gameOver == false ){
while ( SDL_PollEvent(&gameEvent) != 0 ){
if ( gameEvent.type == SDL_QUIT ){
gameOver = true;
}
if ( gameEvent.type == SDL_KEYUP ){
if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
gameOver = true;
}
}
//mouse event
if ( gameEvent.type == SDL_MOUSEMOTION ) {
px = gameEvent.motion.x;
py = gameEvent.motion.y;
}
}
for(int i = 0 ; i < 4 ;i++)
{
if ( atX[i] < px )
atX[i]++;
if ( atX[i] > px )
atX[i]--;
if ( atY[i] < py )
atY[i]++;
if ( atY[i] > py )
atY[i]--;
}
//clip dots.
for ( int i = 0; i < 4; i++ )
sprite.blit(atX[i], atY[i], fromX[i], fromY[i], IMG_WIDTH, IMG_HEIGHT,2,2);
//Draw dots and screen.
screen.flip();
}

return 0;
}
连接失效!
谢谢你的回答
还有这里是不是写多了?
if ( SDL_Init(SDL_INIT_VIDEO < 0 ) )
throw SDL_GetError();
难道不是
if ( SDL_Init(SDL_INIT_VIDEO )< 0 )
throw SDL_GetError();

我把
//key event to move image.
keys = SDL_GetKeyState(0);
if ( keys[SDLK_UP] || keys[SDLK_w] ){
ypos -= 1;
}
if ( keys[SDLK_DOWN]|| keys[SDLK_s] ){
ypos += 1;
}
if ( keys[SDLK_LEFT]|| keys[SDLK_a] ){
xpos -= 1;
}
if ( keys[SDLK_RIGHT]|| keys[SDLK_d] ){
xpos += 1;
}

改成
//key event to move image.
keys = SDL_GetKeyState(0);
if ( keys[SDLK_UP] || keys[SDLK_w] ){
ypos -= 3;
}
if ( keys[SDLK_DOWN]|| keys[SDLK_s] ){
ypos += 3;
}
if ( keys[SDLK_LEFT]|| keys[SDLK_a] ){
xpos -= 3;
}
if ( keys[SDLK_RIGHT]|| keys[SDLK_d] ){
xpos += 3;
}
以后出现叠影。如果用变量来代替数字来实现变速叠影效果就更明显。
我想知道是为什么?显卡刷新速度不够快么?
wangyy05721984你遇到的问题很可能blitSurface()做的事情是把源图像的首地址给了目标指针.而并非是新开了空间来存放整张图像的数据.如果只是赋勒令指针那么你的情况是理所应当的.因为你改变任何一个surface都是在改变一张图的内容.
抱歉……最后那行我没仔细看。。。
作者写的很清楚啊。。。
谢谢上面这位朋友wintry
照做了,g++编译出错,找不到SDL_Init和SDL_Quit
我已经把它们加到include里出了啊。。。
同时头文件引用也是"SDL/SDL.H"
错误提示如下:
I:\MinGW Progect>g++ -o main main.cpp
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc5wptK9.o:main.cpp:(.text+0x142): undefined
reference to `SDL_Init'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/cc5wptK9.o:main.cpp:(.text+0x22d): undefined
reference to `SDL_Quit'
H:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.tex
t+0x104): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status