๊ทธ์ €๊ป˜ ๊ทธ๋ž˜ํ”ฝ ์ถœ๋ ฅํ•˜๊ธฐ 1ํŽธ์„ ํฌ์ŠคํŒ… ํ–ˆ์—ˆ๋Š”๋ฐ ์†Œ์Šค๊ฐ€ ์—†์—ˆ์ฃ ? ์–ด์ œ ์˜ฌ๋ฆฌ๋ ค ํ–ˆ๋Š”๋ฐ ์ผ์ด ์ข€ ๋ฐ”๋น ์„œ ์˜ค๋Š˜ ํฌ์ŠคํŒ…ํ•ฉ๋‹ˆ๋‹ค.

 

์ž!!!!

 

์˜ค๋Š˜์€ ์ œ๊ฐ€ ๋งŒ๋“  ์†Œ์Šค์™€ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ชจ๋‘ ๊ณต์œ ํ•  ์˜ˆ์ •์ด๋‹ˆ ์ž˜ ๋”ฐ๋ผ์™€๋งŒ ์ฃผ์‹ ๋‹ค๋ฉด ์—ฌ๋Ÿฌ๋ถ„๋“ค๋„ ๋ฉ‹์ง„ ๊ฒŒ์ž„์„ ๋งŒ๋“œ์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค ใ…‹ใ…‹

( ์ €๋„ ์ฒ˜์Œ์ธ๋ฐ ์ด๋Ÿฐ ๋ง์„ ํ•˜๊ณ ์žˆ๋„ค์š” ใ…‹ใ…‹ใ…‹)

 

์ €์™€ ๊ฐ™์€ ์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  libGDX๊ฐ€ ์„ค์น˜๋˜์–ด์žˆ์œผ๋ฉฐ ์ด๊ณณ์˜ ์„ค์ •(assets)์„ ๋˜‘๊ฐ™์ด ํ•˜์…จ๋‹ค๋Š” ๊ฐ€์ •ํ•˜์— ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ํ…Œ์ŠคํŠธ๋Š” ์•ˆ๋“œ๋กœ์ด๋“œ ํฐ์ด ์•„๋‹Œ ๋ฐ์Šคํฌํƒ‘์—์„œ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ( ์•„์ง ํฐ์—์„œ๋Š” ํ…Œ์ŠคํŠธ๋ฅผ ๋ชปํ•ด๋ดค์Šต๋‹ˆ๋‹ค. )

 

 

์งˆ๋ฌธ ์žˆ์œผ์‹œ๋ฉด ๋Œ“๊ธ€ ๋‚จ๊ฒจ์ฃผ์„ธ์š”.

 

๊ทธ๋Ÿผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

 

์˜ค๋Š˜ ๋ณด์‹œ๊ฒŒ๋  ์†Œ์Šค๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์‹คํ–‰์ด ๋ฉ๋‹ˆ๋‹ค.

 

 

 

๋•…์€ ์™ผ์ชฝ์œผ๋กœ ๊ณ„์† ์›€์ง์ด๋Š” ๊ฒƒ ์ฒ˜๋Ÿผ ๋ณด์ด๊ณ  ์ผ€๋ฆญํ„ฐ๋Š” ์™ผ์ชฝ, ์˜ค๋ฅธ์ชฝ ํ™”์‚ดํ‘œ๋กœ ์ด๋™์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

 

1. ์ถ”๊ฐ€๋œ ํŒŒ์ผ ๋ฐ ํด๋ž˜์Šค ( ์†Œ์Šค ์‹คํ–‰์— ํ•„์š”ํ•œ ์ถ”๊ฐ€๋œ ์ด๋ฏธ์ง€ ํŒŒ์ผ์€ ์ฒจ๋ถ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค. )

- carl-carlson.jpg๋Š” ์—†์–ด๋„ ๋˜๋Š” ํŒŒ์ผ์ธ๋ฐ ๋“ค์–ด๊ฐ€์žˆ๋„ค์š” ใ…ˆใ……;;;;

 

 

 

2. ์ฒจ๋ถ€๋œ ํŒŒ์ผ์„ ๋‹ค์šด๋ฐ›์•„ ํ•ด๋‹น ์œ„์น˜ ( android/assets )์— ๋„ฃ์–ด์ฃผ์„ธ์š”.

3. core์— ์žˆ๋Š” ์†Œ์Šค๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

์šฐ์„  Player ์ž…๋‹ˆ๋‹ค.

 

 

 

 

 

 

 

์ž, ํ”Œ๋ ˆ์ด์–ด๋Š” ๊ฒŒ์ž„์† ์ฃผ์ธ๊ณต ์ผ€๋ฆญํ„ฐ์ž…๋‹ˆ๋‹ค. Sprite๋ฅผ ์ด์šฉํ•ด์„œ ๋ฟŒ๋ ค์ค„๊ฑฐ๊ตฌ์š” setBounds๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•ด์„œ ์ผ€๋ฆญํ„ฐ์˜ ์‚ฌ์ด์ฆˆ๋ฅผ ์ง€์ •ํ•ด์คฌ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์™ธ๋ถ€์—์„œ characterSprite๋ฅผ ๋ถˆ๋Ÿฌ์“ธ ์ˆ˜ ์žˆ๋„๋ก getter๋ฅผ ํ•˜๋‚˜ ์„ ์–ธํ•ด์คฌ์ฃ .

 

๋‹ค์Œ์€ CharacterProcessor์ž…๋‹ˆ๋‹ค.

 

 

CharacterProcessor๊ฐ€ InputProcessor๋ฅผ ๊ตฌํ˜„ํ•˜๋ฉด ๊ทธ ์•ˆ์— ๊ฐ์ข… ๋ฉ”์†Œ๋“œ๋“ค์„ ์˜ค๋ฒ„๋ผ์ด๋“œํ•ด์•ผํ•˜๋Š”๋ฐ ์ €๋Š” keyDown๋ฉ”์†Œ๋“œ๋งŒ ๊ตฌํ˜„์„ ํ–ˆ๊ณ  ๋‚˜๋จธ์ง€ ๋ฉ”์†Œ๋“œ๋“ค์€ ๊ธฐ๋ณธ์œผ๋กœ ๋†”๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

 

์ผ๋‹จ ๊ธฐ๋ณธ์ ์œผ๋กœ ํ”Œ๋ ˆ์ด์–ด๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•ด์„œ ๋“ค๊ณ ์žˆ๊ณ  ๊ทธ ํ”Œ๋ ˆ์ด์–ด์—๋Œ€ํ•œ getter์ธ getPlayer()๋ฅผ ๋งŒ๋“ค์–ด์คฌ์Šต๋‹ˆ๋‹ค.

 

์ด์ œ ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์„ ๋ฐ›์•„์„œ ์ผ€๋ฆญํ„ฐ๋ฅผ ์›€์ง์ด๊ธฐ์œ„ํ•ด keyDown๋ฉ”์†Œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

 

์—ฌ๊ธฐ์„œ keycode 21์€ ์™ผ์ชฝ, 22๋ฅผ ์˜ค๋ฅธ์ชฝ ํ™”์‚ดํ‘œ๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค.

์™ผ์ชฝํ™”์‚ดํ‘œ๊ฐ€ ๋ˆŒ๋ฆฌ๋ฉด ์ขŒ์ธก์œผ๋กœ ์ด๋™ํ•˜๋Š”๋ฐ ์กฐ๊ฑด์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ™”๋ฉด์˜ ๊ฐ€์žฅ ์ขŒ์ธก๊นŒ์ง€ ๋„๋‹ฌํ•˜๋ฉด ๋”์ด์ƒ ์›€์ง์ด์ง€ ์•Š๋„๋ก if ์กฐ๊ฑด์„ ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ด๋™ํ•˜๋Š”๊ฒƒ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋™์ผํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์ฒ˜๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

์ž, ์ด์ œ ๋ฉ”์ธํด๋ž˜์Šค์ธ MyGdxGame ํด๋ž˜์Šค๋ฅผ ๋ณด์‹ค๊นŒ์š”?

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture background;
    Texture terrain;
    TextureRegion groundTextureRegion;
    float backgroundPos = 0;
    CharacterProcessor inputProcessor;

    @Override
    public void create () {
        batch = new SpriteBatch();
        background = new Texture("sky2.jpg");
        terrain = new Texture("grey_stone_1.png");
        terrain.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
        groundTextureRegion = new TextureRegion(terrain);
        inputProcessor = new CharacterProcessor();
        Gdx.input.setInputProcessor(inputProcessor);
    }
    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.disableBlending();
        batch.draw(background, 0, 0, 800, 480);
        batch.enableBlending();
        
        // let's draw ground image
        batch.draw(groundTextureRegion, backgroundPos, 0, 800, 100);
        if ( backgroundPos + 800 > 0 && backgroundPos + 800 < 800){
            batch.draw(groundTextureRegion, backgroundPos + 800, 0, 800, 100);
        }

        // let's draw player
        inputProcessor.getPlayer().getCharacterSprite().draw(batch);

        batch.end();

        updateScene();
    }
    private void updateScene(){
        float deltaTime = Gdx.graphics.getDeltaTime();
        backgroundPos -= 200 * deltaTime;
        if ( backgroundPos <= -800 ){
            backgroundPos = 0;
        }
    }
}

 

 

์šฐ์„  create()์—์„œ๋Š” ๋Œ€๋ถ€๋ถ„์˜ ๊ฐ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

 

render()์—์„œ๋Š” ๋ฟŒ๋ ค์ฃผ๋Š” ๊ฒƒ์„ ๋‹ด๋‹นํ•˜๋Š”๋ฐ ๊ฒŒ์ž„์ด ์‹คํ–‰๋˜๋Š”๋™์•ˆ ๋Š์ž„์—†์ด ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์†Œ๋“œ์ธ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

enableBlending์œผ๋กœ ๋ฐฐ๊ฒฝ(sky2.jpg)์œ„์— ๋•…(grey_stone_1.png)๊ณผ ์ผ€๋ฆญํ„ฐ(player.png)๋ฅผ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

 

๋•…์„ ๊ทธ๋ฆด๋•Œ๋Š” batch.draw()์—์„œ TextureRegion์„ ์ด์šฉํ–ˆ๊ณ , ์ผ€๋ฆญํ„ฐ๋Š” Sprite.draw๋ฅผ ์ด์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ  ๋•…์„ ๊ทธ๋ฆด๋•Œ ๋•…์ด ์ขŒ์ธก์œผ๋กœ ๊ณ„์† ์ด๋™ํ•˜๋ฉด์„œ ๋งˆ์น˜ ์ผ€๋ฆญํ„ฐ๊ฐ€ ์šฐ์ธก์œผ๋กœ ์ด๋™ํ•˜๋Š”๊ฒƒ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋„๋ก ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

 

updateScene()์—์„œ ๊ทธ ํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋„๋ก backgroundPos ( ๋•… ๊ทธ๋ฆผ์ด ๋ฟŒ๋ ค์งˆ ์œ„์น˜ )๋ฅผ ๋ณ€๊ฒฝํ•ด์ฃผ๊ณ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์ž, ๊ทธ๋Ÿฐ๋ฐ ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํ™”์‚ดํ‘œ๋ฅผ ๊ณ„์† ๋ˆ„๋ฅด๊ณ  ์žˆ์–ด๋„ ํ•œ๋ฒˆ ๋ฐ–์— ์›€์ง์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

 

์ด๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ๋‹ค์Œ ํฌ์ŠคํŒ…์—์„œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ์•Œ๋ ค๋“œ๋ฆฌ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ ์˜ค๋Š˜๋„ ์ฆํ”„ํ•˜์‹œ๊ธธ ~ ^-^

 

์ง€๊ธˆ๊นŒ์ง€ libGDX๋ฅผ ๋…ํ•™ํ•˜๊ณ ์žˆ๋Š” ์ผ€์ด์น˜์˜€์Šต๋‹ˆ๋‹ค~

 

P.S : ๋„์›€์ด ๋˜์…จ์œผ๋ฉด ๋Œ“๊ธ€ ํ•˜๋‚˜ ๋‚จ๊ฒจ์ฃผ์„ธ์š” ^-^

 

 

 

 

 

 

[[ ์›๋ณธ ์ด๋ฏธ์ง€ ํŒŒ์ผ์ฒจ๋ถ€ ]]