크리티컬섹션 :: Phaser Js 코드 템플레이트 (Sprite)

달력

92024  이전 다음

  • 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

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 마스터킹
|