HTML5GAME :: HTML5GAME

달력

82025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

Insert Image Into Library

설명 : 이미지를 라이브러리에 추가하고 코드에서 사용할 수 있도록합니다.

도움말 : 프리로드 섹션에서 사용하십시오.

game.load.image(library_key,path_to_image);


Add Image to the Stage

설명 : 스프라이트를 스테이지에 추가

this.char1=game.add.sprite(x,y,library_key);

Preload Sprite Sheet

설명 : 스프라이트 시트를 라이브러리에 미리로드합니다.

game.load.spritesheet('ref_name', 'pathto.png', sprite_width, sprite_height, number_of_cells);


Set Sprite Top Position

설명 : 스프라이트와 맨 위의 거리를 설정합니다.

this.char1.y=top_postion;


Set the Left Position of a Sprite

설명 : 스프라이트의 왼쪽 위치를 설정합니다.

this.char1.x=left_position;


Set the registration point for a sprite

설명 : 스프라이트의 포인트를 설정합니다. 예를 들어 앵커를 0,0으로 설정하면 스프라이트의 왼쪽 위 모서리에 위치 지정이 적용됩니다. 앵커를 0.5,0.5로 설정하면 스프라이트 중간에 위치가 적용됩니다.

this.char1.anchor.setTo(left,top);


Add an animation to a sprite

설명 : 스프라이트의 애니메이션을 정의합니다.

mysprite.animations.add('walk', frame_array, frames_sec,loopBoolean);


Play an animation

설명 : .animations.add에 의해 정의 된 스프라이트에서 애니메이션을 재생합니다.

mysprite.animations.play('animation name');


Add a mask to a sprite

설명 : 그래픽을 부분적으로 가릴 마스크를 추가합니다.

// A mask is a Graphics object

    mask = game.add.graphics(0, 0);

    // Shapes drawn to the Graphics object must be filled.

    mask.beginFill(fill_color);

    // Here we'll draw a circle

    mask.drawCircle(left, top, radius);

    // And apply it to the Sprite

    sprite.mask = mask;


Set sprite frame

설명 : 간단한 이미지 대신 스프라이트 시트를 사용하는 스테이지에 스프라이트를 추가하면 표시되는 프레임을 선택할 수 있습니다

sprite.frame=frame_number;


Add a group

설명:

var myGroup=game.add.group();

myGroup.add(sprite);


Add a Tilesprite

설명 : 여러개로 결합 된 스프라이트를 추가합니다. 배경 스크롤에 사용됩니다.

this.tileSprite = game.add.tileSprite(x, y, width, height, 'key');


Prototype template

설명 : 이것을 사용하여 스프라이트에 대한 prefab/class 만들기

var Monster = function(x=0, y=0, frame=0) {

  Phaser.Sprite.call(this, game, x, y, 'monster', frame);

  // initialize your prefab here

};

Monster.prototype = Object.create(Phaser.Sprite.prototype);

Monster.prototype.constructor = Monster;

Monster.prototype.update = function() {

  // write your prefab’s specific update code here

};


Create sprite in group

설명:

group.create(x, y,'key');


Loop through group

설명:

myGroup.forEach(function(item) {        

        }.bind(this));


Create multiple

설명:

myGroup.createMultiple(20, 'myKey', 0, false);


Detect the end of an animation

설명 : 애니메이션이 완료되면 함수를 호출합니다.

myAnimation.onComplete.add(function, scope);


Load a sprite sheet with json

설명 : JSON 데이터로 스프라이트 시트를 로드합니다.

game.load.atlasJSONHash('letters',"images/main/letters.png","images/main/letters.json");



Posted by 마스터킹
|

Phaser Js 로 게임 개발을 할때, Start 부분에서 사용되는 기본적인 코드에 대해서 알아봅시다.


Blank State

설명 : 필수 기능이있는 빈 상태 템플릿입니다.

var StateMain={      

   preload:function()

    {      

    },  

    create:function()

    {      

    },  

    update:function()

    {              

    }      

}


Switch states

설명 : 상태를 변경합니다. 예를 들어 게임이 종료 된 경우 game.state.start ( "StateGameOver")를 호출 할 수 있습니다.

game.state.start(state_name);


Start for Desktop

설명 : Phaser Js를 시작하는 데 필요한 기본 파일입니다.

var game;

window.onload = function()

{

    game=new Phaser.Game(480,640,Phaser.AUTO,"ph_game");

    game.state.add("StateMain",StateMain);

    game.state.start("StateMain");

}


Start for Dekstop/Mobile

설명 : 모바일을 지원하는 Phaser Js를 시작하는 데 필요한 기본 파일입니다.

var game;

var useLandscape=false;

window.onload = function () {

var isMobile=navigator.userAgent.indexOf("Mobile");

if (isMobile>-1)

     {

        isMobile=true;

     }

     else

     {

        isMobile=false;

     }

    if (isMobile==false) {

        //desktop laptop

        if (useLandscape == true) {

            game = new Phaser.Game(640, 480, Phaser.AUTO, "ph_game");

        } else {

            game = new Phaser.Game(480, 640, Phaser.AUTO, "ph_game");

        }

    } else {

        //mobile device

        game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, "ph_game");

    }

    game.state.add("StateMain",StateMain);

    game.state.start("StateMain");

}


Basic HTML

설명: Phaser Js 용 html

<!DOCTYPE html>

<html lang="">

<head>

    <meta charset="UTF-8">

    <title>Game Title Here</title>

    <script src="js/phaser.min.js">

    </script>

    <script src="js/main.js"></script>  

</head>

<body>

</body>

</html>


Full Screen Meta Tag

설명: 모바일 용 전체 화면에 html을 삽입하는 메타 태그

<meta name="viewport" content="user-scalable=0, initial-scale=1,minimum-scale=1, maximum-scale=1, width=device-width, minimal-ui=1">


Sample Init State

설명 :이 샘플을 사용하여 init 상태를 만듭니다. 초기화 상태는 실행을위한 베어 본 코드를 설정하고 로드 상태를 준비합니다.

var StateInit = {


    preload: function () {

        game.load.image("loadingEmpty", "images/loading/progress_none.png");

        game.load.image("loadingFull", "images/loading/progress_all.png");

        game.scale.forceOrientation(true, false);

        game.scale.enterIncorrectOrientation.add(this.wrongWay, this);

        game.scale.leaveIncorrectOrientation.add(this.rightWay, this);

    }

    , create: function () {

        game.state.start("StateLoad");

    }

    , update: function () {

    }

    , rightWay: function () {

        document.getElementById("wrong").style.display = "none";

    }

    , wrongWay: function () {

        document.getElementById("wrong").style.display = "block";

    }

}


Samepl Load State

설명 :로드 상태는 게임을 시작하기 전에 모든 것을 미리로드 할 수있게합니다.

var StateLoad = {

    preload: function () {

        var empty = game.add.image(0, 0, "loadingEmpty");

        var full = game.add.image(0, 0, "loadingFull");

        empty.x = game.world.centerX;

        empty.y = game.world.centerY;

        empty.anchor.set(0.5, 0.5);

        full.anchor.set(0, 0.5);

        full.x = game.world.centerX - empty.width / 2;

        full.y = empty.y;

        game.load.setPreloadSprite(full);

        //PRELOAD EVERYTHING HERE

    },

    create: function () {

        game.state.start("StateTitle");

    },

    update: function () {

    }

}

Posted by 마스터킹
|

phaser를 배우는 개발자가 가장 먼저 배워야 할 것은 phaser에 이미지를 추가하는 방법입니다. 그리고 그과정은 정말 쉽습니다. 이미지를 라이브러리에로드 한 다음 스테이지에 배치하는 2 단계 프로세스입니다. 저는 그것을 초보자를위해 4단계 과정으로 정리해 보겠습니다.


1 단계. 기본 템플릿 다운로드

템플릿 폴더의 이름을 프로젝트 이름 (예 : ImageTest)으로 바꾸고 좋아하는 편집기로 폴더를 엽니다.


2 단계. 프로젝트에 이미지 추가하기

프로젝트 내부에 폴더를 만들고 내부에로드 할 이미지를 추가하십시오.

















3 단계. 이미지를 라이브러리에 로드하십시오.

이 코드를 stateMain.js 파일의 preload 함수 안에 넣으십시오.

game.load.image("monster","images/monster.png");


game.load.image는 다음과 같이 작동합니다.

game.load.image(unique_key,path_to_image);


4 단계. 이미지를 캔버스에 놓습니다.

create 함수 내에서 game.add.sprite 코드를 사용하십시오.

game.add.sprite(100,200,"monster");


game.load.sprite는 다음과 같이 작동합니다.

game.add.sprite(x,y,unique_key);



다음은이 작업을 수행하는 방법을 보여주는 비디오입니다.



Posted by 마스터킹
|