[React Native] 레트로 게임 UI 만들기

in #kr6 years ago (edited)


Illustration © Codeman38

어렸을 때 Final Fantasy와 같은 RPG 게임을 좋아했습니다. 옛날 레트로 느낌을 살려서, Final Fantasy UI 처럼 보이는 컨테이너를 만들어 봅니다.


* * *

프로젝트 생성하기

expo-cli를 사용하여 프로젝트를 생성합니다. 프로젝트 명은 ffcontainer라고 하였습니다.

$ expo init ffcontainer

 

라이브러리 설치

이번에는 styled-components 모듈을 설치하여 사용해 봅니다.

$ yarn add styled-components

 

FFContainer 만들기

App.js 파일의 내용을 지우고 아래와 같이 작성합니다. 먼저 필요한 모듈을 import 합니다.

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { Constants, LinearGradient } from 'expo';
import styled from 'styled-components';


그리고 styled-components를 사용하여, 앱 컨테이너를 담당할 <Container> 를 작성합니다. styled-components를 사용하면 다음과 같이 CSS 비슷하게 사용할 수 있습니다.

const Container = styled.View`
  flex: 1;
  background-color: black;
  paddingTop: ${Constants.statusBarHeight};
`;


styled-components로 만든 <Container>가 어떻게 렌더링되는지 확인해봅니다.

export default class App extends React.Component {

  render() {
    return (
      <Container>
      </Container>
    );
  }
};

 

이제 본격적으로 FFContainer를 만들어 봅니다. 아래와 같이 작성합니다.

const FFContainer = styled.View`
  border-radius: 8;                         
  border-width: 4;
  border-color: #e7dfe7;
  border-style: solid;
  background-color: #e7dfe7;    
  margin-horizontal: 10; 
  margin-vertical: 10;
`;

const styles = StyleSheet.create({
  FFContents: {
    padding: 10, 
    borderRadius: 5,
  }
});

const GRADIENT_COLOR = ['#6c6eb2', '#181870', '#000028'];

export default class App extends React.Component {
  render() {
    return (
      <Container>
        <FFContainer>
          <LinearGradient 
            style={styles.FFContents}
            colors={GRADIENT_COLOR}>
            <Text style={{color:'white'}}>Hello World!</Text>
          </LinearGradient>
        </FFContainer>
      </Container>
    );
  }
};

아래와 같이 보여집니다.

 

Fonts 적용하기

이번에는 레트로 감성의 폰트를 적용해봅시다. 구글에서 제공하는 폰트 중에 Press+Start+2P가 있습니다.

Press Start 2P Font를 다운로드 합니다. [여기]에서 다운로드 가능합니다.


App.js 를 수정합니다. expo에서 Font 모듈을 추가로 import 합니다.

import { 
  Constants, 
  LinearGradient, 
  Font,       // here
} from 'expo';


그리고 Font.loadAsync를 사용하여 assets 폴더에 있는 Font 파일을 가져옵니다. Font 파일 로딩이 완료되기 전에 Font 를 사용하면 에러가 발생합니다. 그래서state.fontLoaded로 Font 파일 로딩 완료 여부를 판단할 것 입니다.

export default class App extends React.Component {

  state = {
    fontLoaded: false // here
  }

  async componentWillMount() {
    await Font.loadAsync({
      'PressStart2P': require('./assets/PressStart2P.ttf'),
    });

    this.setState({ fontLoaded: true });
  }

    // (...)

expo에서 커스텀 폰트 사용방법은 Using Custom Fonts 문서를 참고하였습니다.


<Text> 에 'Hello World!' 를 출력하여 Font를 확인해봅니다.

export default class App extends React.Component {

    // (...)
    
  render() {
    if(this.state.fontLoaded) {
      return (
        <Container>
          <FFContainer>
            <LinearGradient 
              style={ styles.FFContents }
              colors={ GRADIENT_COLOR }>
              <Text style={{color:'white', fontFamily:'PressStart2P'}}>Hello World!</Text>
            </LinearGradient>
          </FFContainer>
        </Container>
      );
    }
    return null;
  }
};

 

스팀잇 프로필 화면 만들기

스팀잇 프로필을 아래와 같은 UI로 만들어 보았습니다. 화면에서 명성(Reputation)을 LV라고 표현해보았습니다. 게임 화면처럼 보이나요? ㅎㅎ


위 코드 내용은 snack.expo.io에서 확인할 수 있습니다.

여기까지 읽어주셔서 감사합니다.


Sponsored ( Powered by dclick )

dclick-imagead

Sort:  

오 대박인데요! 화면 아주 이쁩니다. 예전부터 느낀거지만 개발뿐만 아니라 UI감각도 있으신것 같아요. 이건 진짜 함 따라 해봐야겠네요.

아 진짜 이런글 유토피안 튜토리얼로 쓰시면 정말 좋을텐데.

ps. 이제보니 폰트이름도 대박이네요ㅎㅎ

감사합니다. 코딩보다 UI 디자인하는데 시간을 더 많이 사용하고 있어요. 저는
감동을 주는 감성 코딩을 지향합니다. ㅋ

그리고 폰트 이름이 정말 재미있습니다. 폰트 이름만 봐도 옛날 오락실 게임 UI가 생각납니다. ㅋㅋㅋ

그나저나 빨리 스팀잇 경험치를 쌓아서 레벨 70을 찍고 싶네요.

곰돌이가 @anpigon님의 소중한 댓글에 $0.016을 보팅해서 $0.007을 살려드리고 가요. 곰돌이가 지금까지 총 3571번 $42.418을 보팅해서 $44.398을 구했습니다. @gomdory 곰도뤼~

곰돌이가 @blockchainstudio님의 소중한 댓글에 $0.016을 보팅해서 $0.007을 살려드리고 가요. 곰돌이가 지금까지 총 3564번 $42.331을 보팅해서 $44.324을 구했습니다. @gomdory 곰도뤼~

dos 게임 환경 같은 폰트네요. ^^

도시 시절에 많이 보던 폰트죠. ㅎㅎ
제가 요즘 이런 레트로 느낌의 UI가 좋더군요.

곰돌이가 @anpigon님의 소중한 댓글에 $0.015을 보팅해서 $0.008을 살려드리고 가요. 곰돌이가 지금까지 총 3551번 $42.187을 보팅해서 $44.169을 구했습니다. @gomdory 곰도뤼~

Congratulations @anpigon! You received a personal award!

DrugWars Early Access
Thank you for taking part in the early access of Drugwars.

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Are you a DrugWars early adopter? Benvenuto in famiglia!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!


@anpigon님 넘치는 사랑 감사합니다~

우와 언제 따라해볼래요ㅋ.ㅋ 감사합니다

Posted using Partiko iOS

세대를 아우르는, 뉴트로 디자인 라는 글을 보고,
모바일앱 UI도 레트로 느낌이 나게 만들어 보았습니다.
재미있게 봐주셔서 감사합니다. ㅎㅎ

뉴트로는 ‘뉴(New)+레트로(Retro)’가 합쳐진 합성어라고 합니다.

링크 주셔서 감사하게도 저도 한번 잘 읽어보겠습니다😊 왠지 저도 뉴트로 코드와 잘 맞을 것 같은데요ㅎ.ㅎ

Posted using Partiko iOS

곰돌이가 @anpigon님의 소중한 댓글에 $0.015을 보팅해서 $0.008을 살려드리고 가요. 곰돌이가 지금까지 총 3555번 $42.230을 보팅해서 $44.218을 구했습니다. @gomdory 곰도뤼~

이런 재밓는 코드 올려주셔서 감사합니다~

Posted using Partiko iOS

레트로 디자인을 좋아하는군요. 코딩으로 좀더 재미난 걸 만들어 보고싶어요. ㅎㅎ

곰돌이가 @anpigon님의 소중한 댓글에 $0.015을 보팅해서 $0.008을 살려드리고 가요. 곰돌이가 지금까지 총 3554번 $42.215을 보팅해서 $44.210을 구했습니다. @gomdory 곰도뤼~

Hi @anpigon!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 2.986 which ranks you at #10938 across all Steem accounts.
Your rank has improved 57 places in the last three days (old rank 10995).

In our last Algorithmic Curation Round, consisting of 205 contributions, your post is ranked at #150.

Evaluation of your UA score:
  • Only a few people are following you, try to convince more people with good work.
  • The readers like your work!
  • You have already shown user engagement, try to improve it further.

Feel free to join our @steem-ua Discord server

짱짱맨 호출에 응답하였습니다.

멋지네요 ㅎㅎ

플러터 다시 좀 해야 되는데 ... 요즘은 또 드럭워에 빠졌네요 ㅜㅜ

마약 팔아서 스팀은 많이 모으셨나요?
한동안 스팀몬스터 하시더니, 이제는 마약전쟁에 빠지셨군요. ㅎㅎ

저도 요즘 슬럼프가 와서 코딩이 잘 안 되네요.
그나저나 플러터는 요새 근황이 어떤가요? 아직도 플러터 한글 문서는 많이 안보이네요. ㅠㅠ

미약은 전 수익권이긴 하죵 :) 초반부터 해서

그리고 플러터는 한글문서는 아직 거의 없지만

디스코드문의도 되고 영문 document가 워낙 잘되서 공부하긴 수월한거 같네요 ㅋ

Posted using Partiko Android

마약으로 수익을 내셨군요. 축하드립니다. ㅎㅎ
저도 영문 document가 워낙 잘되어 있어서, 역시 구글이구나 생각했습니다.
하지만 제 영어 실력으로는 영어 문서는 읽는데 시간이 너무 오래 걸립니다. ㅠㅠ
그래서 플러터는 원사마님이 올리는 포스팅만 읽고 있어요. ㅎㅎ

Congratulations @anpigon! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 7000 upvotes. Your next target is to reach 8000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Vote for @Steemitboard as a witness and get one more award and increased upvotes!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63098.06
ETH 2563.30
USDT 1.00
SBD 2.83