SDL之鼠标移动事件

这节没有什么特殊的东西,需要注意的是,当鼠标移动时,会产生影子,这是需要更新之前,将背景进行刷新

#include "SDL.h"
#include "SDL_image.h"
int main(int argc, char* argv[])
{
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Window* window = SDL_CreateWindow("hello SDL", 100, 100, 600, 800, SDL_WINDOW_SHOWN);
	SDL_Surface* surface = SDL_GetWindowSurface(window);
	SDL_Surface* picture = SDL_LoadBMP("C:\\Users\\xxxxx\\Desktop\\1.bmp");
	SDL_BlitSurface(picture, NULL, surface, NULL);
	SDL_UpdateWindowSurface(window);
	SDL_Rect rect;
	rect.x = 0;
	rect.y = 0;

	SDL_Event event;
	bool quit = false;
	while (false == quit)
	{
		while (SDL_PollEvent(&event))
		{
			if (SDL_QUIT == event.type)
			{
				quit = true;
			}
			else if (SDL_MOUSEMOTION == event.type)
			{
				int x = event.motion.x - picture->w / 2;
				int y = event.motion.y - picture->h / 2;
				printf("x = %d,y=%d",x,y);
				rect.x = x;
				rect.y = y;
				SDL_FillRect(surface, NULL, 0); //去除尾际
				SDL_BlitSurface(picture, NULL, surface, &rect);
				SDL_UpdateWindowSurface(window);
			}
		}
	}

	SDL_FreeSurface(surface);
	SDL_FreeSurface(picture);
	SDL_DestroyWindow(window);
	SDL_Quit();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值