ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • SFML / 1. 게임시작화면 구현
    활동 기록 😵‍💫/SFML 테트리스 2023. 2. 8. 01:38

    먼저 글씨체를 다시 바꿔주었다. 

    if (!font.loadFromFile("C:/Users/User/Downloads/DungGeunMo TTF/DungGeunMo.ttf"))
    		throw exception("font error");

    그리고 밑에 안내멘트? 도 추가했다.

    textprint(text2, font, 30, 50, 300, Color::Black, Color::Black, hi);
    string hi = "PRESS THIS BUTTON TO START !";

    처음에는 스페이스 바를 누르면 화면이 전환되게 하려 했으나... 나중에 바꾸게 된 이유가 나온다..!(사실 지금 생각해보면 스페이스바로 해도됨) 아무튼

     

    그다음 상단의 제목에 효과를 주고 싶었다.

    글씨가 크니까 이동하면서 보이게끔? 

    text.move(x,y) 함수를 사용하고 , text의 위치를 처음부터 굉장히 오른쪽으로 설정하여 나타나도록 했다.

    이전의 글을 참고하면 인자가 무엇을 뜻하는지 알 수 있음

    textprint(text, font, 100, 700, 30, Color::Green, Color::Black, comment);

    여기까지 한 결과물 

    (밑에 글씨도 떴는데 못찍었당) 

    아무튼 그러고..

    이제 게임 화면으로 전환하도록 하려했다 !

    1. window.clear() 으로 화면 초기화 ...

    2. 키보드를 누르면 글씨가 사라지도록 

        while (window.pollEvent(event)) {
             
             }
          text.move(-1, 0);
          window.clear(Color::White);
          window.draw(text);
          window.draw(text2);
    
          window.display();
    
          if (Keyboard::isKeyPressed(Keyboard::Space)) {
             window.clear(Color::Green);
    
             window.display();
             
    
          }
          
    
       }

    여러 방법을 찾아 봤는데 다 안됐다 

    키보드를 누르는 조건을 주면 초기화 하고 싶었는데 누르고 있는 ! 순간만 된다 ㅠ(게임캐릭터 이동처럼..)

    참나 

    그리고 글씨가 사라지도록 하는 효과는 못찾았다.. 

    멀리 이동시킨다 쳤을 때 코드도 복잡해지고.. 새로운 화면을 시작하는게 아니라는것이 뭔가 찝찝해서... 

    계속.. 찾은 결과 

    window.create 라고 ㅠ 함수를 조건문에 넣어서 하면 됐다....( window를 처음부터 2개 선언하고 만약에 종료가 되면 새로운 창이 켜지게 ... 하려고 끙끙대고 있었다...)

     

    그런데 또 문제였다. 

    그렇게 하니까 글씨를 움직이는게 안됐다. 

    여기에 넣으면 글씨가 안나타나고 

    저기에 넣으면 밑에 검은 글씨가 안사라지고 

    아니면 렉걸리듯이 미친듯이 깜빡였다. 

     

    그래서 !!!

    움직이도록 하되! 

    마우스 클릭과 동시에 검은색 글자의 위치를 머어얼리 이동시켰다 !

    게임시작화면 완성이다.. 나중에 소리만 추가할꺼,,,버튼 이미지도...(맨마지막 ,,)빠이 

    #include <SFML/Graphics.hpp>
    
    #include <cassert> 
    
    #include <stdio.h>
    
    #include <iostream>
    
    #include <windows.h>
    #include <string>
    #include <exception>
    #include <conio.h>
    
    #include <stdlib.h>
    #include <SFML/Config.hpp>
    #include <SFML/System/Export.hpp>
    
    using namespace std;
    using namespace sf;
    
    //text 함수 
    int textprint(Text& text, Font& font, int size, float x, float y, const Color& color, const Color& outColor, string p) 
    
    {
    	text.setFont(font);
    	text.setCharacterSize(size);
    	text.setPosition(x, y);
    	text.setFillColor(color);
    	text.setOutlineColor(outColor);
    	text.setOutlineThickness(1.f);
    	text.setString(p);
    	return 0;
    
    
    }
    
    int main() {
    
    	Text text;
    	Text text2;
    	Uint8 r = 0, g = 0, b = 0;
    	string comment = "tetris Game Start";
    	string hi = "PRESS THIS BUTTON TO START !"; //스페이스 바를 누르면 게임시작
    	int x = 0, y = 0;
    	Clock clock;  //경과 시간 측정
    	float interval = 0;
    
    	RenderWindow window(VideoMode(500, 500), "tetris");
    	
    	
    	window.setFramerateLimit(60);
    
    	//시작화면 text 
    	Font font;
    	if (!font.loadFromFile("C:/Users/User/Downloads/DungGeunMo TTF/DungGeunMo.ttf"))
    		throw exception("font error");
    	textprint(text, font, 100, 700, 30, Color::Green, Color::Black, comment);
    	textprint(text2, font, 30, 50, 300, Color::Black, Color::Black, hi);
    	
    
    	
    	
    
    
    	while (window.isOpen()) {
    		text.move(-1, 0);
    
    		window.clear(Color::White);
    		window.draw(text);
    		window.draw(text2);
    		window.display();
    	
    		Event event;
    		
    		while (window.pollEvent(event)) {
    			
    
    			switch (event.type) {
    			
    			case Event::Closed:
    					window.close();
    					break;
    			case Event::MouseButtonPressed:
    				if (event.mouseButton.button == Mouse::Left) {
    					text2.move(1000, 0);
    					window.create(VideoMode(500, 500), "tetris game");
    					window.clear(Color::Black);
    					window.display();
    					break;
    				}
    
    			}
    			
    			
    			}
    
    
    				}
    
    
    		return 0;
    	}

     

    땡스투 동그라미.. 

     

     

     

Diseñada por Tistory.