var game = cc.Layer.extend({
init:function () {
this._super();
backgroundLayer = cc.LayerColor.create(new cc.Color(40,40,40,255), 320, 480);
var target = cc.Sprite.create("resources/doge.png"); /*child to clip*/
var mask = cc.Sprite.create("resources/doge-mask.png"); /*mask*/
var maskedFill = new cc.ClippingNode(mask);
maskedFill.setAlphaThreshold(0.9);
maskedFill.addChild(target);
maskedFill.setPosition(144, 224);
backgroundLayer.addChild(maskedFill,0);
this.addChild(backgroundLayer);
}
});
'cocos2D'에 해당되는 글 4건
- 2017.02.23 [cocos2d-js] 이미지 mask 만들기
- 2016.07.27 jsb방식에서 XMLHttpRequest 안될때
- 2015.10.20 [cocos2d]안드로이드 App 개발시 cc.LabelTTF 의 폰트 적용 방법
- 2014.02.19 [cocos2d]애니메이션 스프라이트를 메뉴 버튼으로 사용 하기
*안드로이드 App 개발시 cc.LabelTTF 의 폰트 적용 방법
-네이티브 앱일 경우와 html5 웹으로 보여 질때를 구분 하여, 앱일 경우에는 폰트의 이름과 확장자까지 기입을
해 준다.
if (cc.sys.isNative)
{
this.quiz_txt = cc.LabelTTF.create("게임 시작", "res/fonts/HYBDAM.ttf", 40, cc.size(320, 110), cc.TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_CENTER);
} else {
this.quiz_txt = cc.LabelTTF.create("게임 시작", "HYBDAM", 40, cc.size(320, 110), cc.TEXT_ALIGNMENT_CENTER, cc.VERTICAL_TEXT_ALIGNMENT_CENTER);
}
this.quiz_txt.setColor(cc.color(255,255,255));
this.quiz_txt.enableStroke(cc.color(0,110,208), 4);
this.quiz_txt.x = 500;
this.quiz_txt.y = 300;
this.addChild(this.quiz_txt);
# 애니메이션 스프라이트를 MenuItemSprite 에 적용 하여 버튼을 만들자
1. 우선 애니메이션 스프라이트인 StartButtonSprite 파일을 만든다. 꼭, ctor 함수 부분에 이미지 한장 짜리 스프라이트를
배치 한 후 애니메이션을 실행 해야 한다.
var StartButtonSprite = cc.Sprite.extend
({
ctor:function()
{
this._super();
cc.associateWithNative(this, cc.Sprite);
//만들어 놓은 StartButtonBasic 스프라이트
var pFrame = cc.SpriteFrameCache.getInstance().getSpriteFrame("StartButtonBasic");
this.initWithSpriteFrame(pFrame);
this.play();
return true;
},
play:function()
{
//만들어 놓은 StartButtonBasic 스프라이트
var animation = cc.AnimationCache.getInstance().getAnimation("StartButton");
var animate = cc.Animate.create(animation);
this.runAction(cc.RepeatForever.create(animate));
}
});
2. MenuItemSprite 만들기
var startBtnImg = new StartButtonSprite();
var menuItem = cc.MenuItemSprite.create(startBtnImg, null, this.goGame, this);
this.startBtn = cc.Menu.create(menuItem);
this.startBtn.setPosition(cc.p(GD.WW*0.5, 50));
this.addChild(this.startBtn);