자신을 가르치고 있습니다. 자습서를 따라 화면을 돌아 다니며 이미지를 이동했습니다. 이제는 직접 해보고 코드를 모듈화하는 방법을 이해하고 코드를 어떻게 진행하는지 알고 있습니다.구조체의 요소를 정의하려고 할 때 계속 오류가 발생합니다.
구조체를 생성하여 플레이어 좌표를 가져 와서 내 game_loop.h 파일로 호출했습니다. 하지만 그것은 struct에서 변수를 설정할 수 없습니다. 간결하게 유지하기 위해 중요한 비트 만 포함하려고했습니다. 전체 코드를 게시해야하는지 알려주세요. 내가 뭘 잘못하고있어.
//includes
#include "game_loop.h"
//main body
int main(int argc, char *argv[])
{
//TODO make game menu and link it here
//TODO make game loop and put it here
initSDL();
renderGame();
handleEvent();
//make game cleanup and put it her
destroySDL();
return 0;
}
INT 헤더 파일 game_loop.h - player.h 파일>
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "player.h"
#define pSIZE 64
#define wWIDTH 1280
#define wHEIGHT 720
//variables for starting SDL
SDL_Event event;
SDL_Window *window = NULL;
SDL_Renderer *render = NULL;
SDL_Surface *bgSurface = NULL;
SDL_Texture *bgTexture = NULL;
SDL_Surface *pSurface = NULL;
SDL_Texture *pTexture = NULL;
int flags = 0; //window flags may need to change in the future
struct Player player;
player.x = 600;
player.y = 300;
void initSDL()
{
//initializing SDL
if(SDL_Init(SDL_INIT_VIDEO)!= 0)
{
printf("ERROR starting SDL: %s\n", SDL_GetError());
}else{printf("Starting SDL: Successful.\n");}
- 당신은 함수의 외부 실행 코드의 라인을 가지고>
struct Player{
int x;
int y;
};
사용중인 코드를 게시 할 수 있습니까?, 코드를 읽을 수 없다면 어떻게 잘못하고 있는지 알 수 있습니까? –
할당하려는 전역 범위. 그것을 방법 안에 넣어 라. 'player.x = 600' – coderredoc
질문에 코드를 추가했습니다. 미안하다. 코딩에 관한 포럼에서 처음으로 질문을한다. 그리고 질문에 대한 코드 형식을 지정하는 데 어려움을 겪고 있습니다. 나는 거기에 전체 코드를 넣으려고합니다 – Nelyn