重點是兩個printf的地方,為什么可以輸出1,不能輸出2??
#include"SDL.h" //一個BMP格式的圖片自動向右下角 開始移動,碰到視窗之后,彈開
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int a = 1, b = 1;
SDL_Rect rect;void aaBS();
int main(int argc,char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("automove", 100,100, 800, 600, SDL_WINDOW_SHOWN);
SDL_Surface* surface = SDL_GetWindowSurface(window); SDL_Surface* mesurface = SDL_LoadBMP("me.bmp"); SDL_Renderer* rend = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Texture* me = SDL_CreateTextureFromSurface(rend,mesurface); SDL_Event event; SDL_RenderClear(rend);
rect.x = 1; rect.y = 1;
rect.h = mesurface->h;
rect.w = mesurface->w;
bool quit = false;
while (quit == false) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true; }
SDL_RenderClear(rend);
void aaBS(); printf("1");
SDL_RenderCopy(rend, me, NULL, &rect); } SDL_Delay(5);
SDL_RenderPresent(rend); } SDL_DestroyWindow(window);
SDL_Quit; return 0;}
void aaBS() {
if (rect.x >= 780 || rect.x < 0) {
a = a * (-1); }
else if (rect.y >= 580 || rect.y < 0) {
b = b * (-1); }
rect.x = rect.x + a; rect.y = rect.y + b; printf("2");}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/42576.html
標籤:其它游戲引擎
下一篇:unity尋路
