Add: RoundRectButton

This commit is contained in:
jisangs committed 2018-05-01 19:14:06 +09:00
1 parent 581efd0777
commit eb4eafd7b5
9 files changed
+202 -37

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
/* Phaser v2.10.3 - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */
!function(t){if("object"==typeof exports)module.exports=t();else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.p2=t()}}(function(){return function t(e,i,s){function n(o,a){if(!i[o]){if(!e[o]){var h="function"==typeof require&&require;if(!a&&h)return h(o,!0);if(r)return r(o,!0);throw new Error("Cannot find module '"+o+"'")}var l=i[o]={exports:{}};e[o][0].call(l.exports,function(t){var i=e[o][1][t];return n(i||t)},l,l.exports,t,e,i,s)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o<s.length;o++)n(s[o]);return n}({1:[function(t,e,i){function s(){}var n=t("./Scalar");e.exports=s,s.lineInt=function(t,e,i){i=i||0;var s,r,o,a,h,l,c,u=[0,0];return s=t[1][1]-t[0][1],r=t[0][0]-t[1][0],o=s*t[0][0]+r*t[0][1],a=e[1][1]-e[0][1],h=e[0][0]-e[1][0],l=a*e[0][0]+h*e[0][1],c=s*h-a*r,n.eq(c,0,i)||(u[0]=(h*o-r*l)/c,u[1]=(s*l-a*o)/c),u},s.segmentsIntersect=function(t,e,i,s){var n=e[0]-t[0],r=e[1]-t[1],o=s[0]-i[0],a=s[1]-i[1];if(o*r-a*n==0)return!1;var h=(n*(i[1]-t[1])+r*(t[0]-i[0]))/(o*r-a*n),l=(o*(t[1]-i[1])+a*(i[0]-t[0]))/(a*n-o*r);return h>=0&&h<=1&&l>=0&&l<=1}},{"./Scalar":4}],2:[function(t,e,i){function s(){}e.exports=s,s.area=function(t,e,i){return(e[0]-t[0])*(i[1]-t[1])-(i[0]-t[0])*(e[1]-t[1])},s.left=function(t,e,i){return s.area(t,e,i)>0},s.leftOn=function(t,e,i){return s.area(t,e,i)>=0},s.right=function(t,e,i){return s.area(t,e,i)<0},s.rightOn=function(t,e,i){return s.area(t,e,i)<=0};var n=[],r=[];s.collinear=function(t,e,i,o){if(o){var a=n,h=r;a[0]=e[0]-t[0],a[1]=e[1]-t[1],h[0]=i[0]-e[0],h[1]=i[1]-e[1];var l=a[0]*h[0]+a[1]*h[1],c=Math.sqrt(a[0]*a[0]+a[1]*a[1]),u=Math.sqrt(h[0]*h[0]+h[1]*h[1]);return Math.acos(l/(c*u))<o}return 0==s.area(t,e,i)},s.sqdist=function(t,e){var i=e[0]-t[0],s=e[1]-t[1];return i*i+s*s}},{}],3:[function(t,e,i){function s(){this.vertices=[]}function n(t,e,i,s,n){n=n||0;var r=e[1]-t[1],o=t[0]-e[0],h=r*t[0]+o*t[1],l=s[1]-i[1],c=i[0]-s[0],u=l*i[0]+c*i[1],d=r*c-l*o;return a.eq(d,0,n)?[0,0]:[(c*h-o*u)/d,(r*u-l*h)/d]}var r=t("./Line"),o=t("./Point"),a=t("./Scalar");e.exports=s,s.prototype.at=function(t){var e=this.vertices,i=e.length;return e[t<0?t%i+i:t%i]},s.prototype.first=function(){return this.vertices[0]},s.prototype.last=function(){return this.vertices[this.vertices.length-1]},s.prototype.clear=function(){this.vertices.length=0},s.prototype.append=function(t,e,i){if(void 0===e)throw new Error("From is not given!");if(void 0===i)throw new Error("To is not given!");if(i-1<e)throw new Error("lol1");if(i>t.vertices.length)throw new Error("lol2");if(e<0)throw new Error("lol3");for(var s=e;s<i;s++)this.vertices.push(t.vertices[s])},s.prototype.makeCCW=function(){for(var t=0,e=this.vertices,i=1;i<this.vertices.length;++i)(e[i][1]<e[t][1]||e[i][1]==e[t][1]&&e[i][0]>e[t][0])&&(t=i);o.left(this.at(t-1),this.at(t),this.at(t+1))||this.reverse()},s.prototype.reverse=function(){for(var t=[],e=0,i=this.vertices.length;e!==i;e++)t.push(this.vertices.pop());this.vertices=t},s.prototype.isReflex=function(t){return o.right(this.at(t-1),this.at(t),this.at(t+1))};var h=[],l=[];s.prototype.canSee=function(t,e){var i,s,n=h,a=l;if(o.leftOn(this.at(t+1),this.at(t),this.at(e))&&o.rightOn(this.at(t-1),this.at(t),this.at(e)))return!1;s=o.sqdist(this.at(t),this.at(e));for(var c=0;c!==this.vertices.length;++c)if((c+1)%this.vertices.length!==t&&c!==t&&o.leftOn(this.at(t),this.at(e),this.at(c+1))&&o.rightOn(this.at(t),this.at(e),this.at(c))&&(n[0]=this.at(t),n[1]=this.at(e),a[0]=this.at(c),a[1]=this.at(c+1),i=r.lineInt(n,a),o.sqdist(this.at(t),i)<s))return!1;return!0},s.prototype.copy=function(t,e,i){var n=i||new s;if(n.clear(),t<e)for(r=t;r<=e;r++)n.vertices.push(this.vertices[r]);else{for(r=0;r<=e;r++)n.vertices.push(this.vertices[r]);for(var r=t;r<this.vertices.length;r++)n.vertices.push(this.vertices[r])}return n},s.prototype.getCutEdges=function(){for(var t=[],e=[],i=[],n=new s,r=Number.MAX_VALUE,o=0;o<this.vertices.length;++o)if(this.isReflex(o))for(var a=0;a<this.vertices.length;++a)if(this.canSee(o,a)){e=this.copy(o,a,n).getCutEdges(),i=this.copy(a,o,n).getCutEdges();for(var h=0;h<i.length;h++)e.push(i[h]);e.length<r&&(t=e,r=e.length,t.push([this.at(o),this.at(a)]))}return t},s.prototype.decomp=function(){var t=this.getCutEdges();return t.length>0?this.slice(t):[this]},s.prototype.slice=function(t){if(0==t.length)return[this];if(t instanceof Array&&t.length&&t[0]instanceof Array&&2==t[0].length&&t[0][0]instanceof Array){for(var e=[this],i=0;i<t.length;i++)for(var s=t[i],n=0;n<e.length;n++){var r=e[n].slice(s);if(r){e.splice(n,1),e.push(r[0],r[1]);break}}return e}var s=t,i=this.vertices.indexOf(s[0]),n=this.vertices.indexOf(s[1]);return-1!=i&&-1!=n&&[this.copy(i,n),this.copy(n,i)]},s.prototype.isSimple=function(){for(var t=this.vertices,e=0;e<t.length-1;e++)for(var i=0;i<e-1;i++)if(r.segmentsIntersect(t[e],t[e+1],t[i],t[i+1]))return!1;for(e=1;e<t.length-2;e++)if(r.segmentsIntersect(t[0],t[t.length-1],t[e],t[e+1]))return!1;returLine truncated
//# sourceMappingURL=phaser.map
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

+19
View File
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- <script src="https://labs.phaser.io/build/phaser-arcade-physics.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/phaser@3.6.0/dist/phaser.min.js"></script>
</head>
<body>
<div id="PhaserSample" style="text-align:center;" />
<script>
$(document).ready(function(){
$.getScript( "phaser_sample_main.js", function() {});
});
</script>
<!-- <script src="./phaser_sample.js"></script> -->
</body>
</html>
@@ -0,0 +1,47 @@
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.setBaseURL('http://labs.phaser.io');
this.load.image('sky', 'assets/skies/space3.png');
this.load.image('logo', 'assets/sprites/phaser3-logo.png');
this.load.image('red', 'assets/particles/red.png');
}
function create ()
{
this.add.image(400, 300, 'sky');
var particles = this.add.particles('red');
var emitter = particles.createEmitter({
speed: 100,
scale: { start: 1, end: 0 },
blendMode: 'ADD'
});
var logo = this.physics.add.image(400, 100, 'logo');
logo.setVelocity(100, 200);
logo.setBounce(1, 1);
logo.setCollideWorldBounds(true);
emitter.startFollow(logo);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

+14 -7
View File
@@ -4,12 +4,6 @@
<meta charset="UTF-8">
<title>Round rect image button test</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/phaser@3.6.0/dist/phaser.min.js"></script>
<script src="./round_rect_button.js"></script>
<script src="./round_rect_button_main.js"></script>
<style>
body{
padding: 0;
@@ -20,9 +14,22 @@
margin: 0 auto;
}
</style>
<!--
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.js"></script>
<!-- <script src="../../resources/js/phaser.min.js"></script> -->
<script src="./round_rect_button.js"></script>
<script src="./round_rect_button_main.js"></script>
</head>
<body>
<div id="Round rect image button test" style="text-align:center;" />
<div id="RoundRectButton" style="text-align:center;" />
</body>
</html>
+80 -13
View File
@@ -1,3 +1,71 @@
class RectSetting {
constructor(width, height, buttonColors) {
this.width = width;
this.height = height;
this.DEFAULT_BUTTON_COLORS = {
over: "#fff", // over
out: "#aaf", // out
down: "#faa", // down
disabled: "#333" // disabled
};
this.DEFAULT_TEXT_COLORS = {
over: "#000", // over
out: "#000", // out
down: "#000", // down
disabled: "#999" // disabled
};
if(buttonColors != null)
this.buttonColors = buttonColors;
else
this.buttonColors = RectSetting.DEFAULT_BUTTON_COLORS;
}
}
RectSetting.DEFAULT_BUTTON_COLORS = {
over: "#fff", // over
out: "#aaf", // out
down: "#faa", // down
disabled: "#333" // disabled
};
RectSetting.DEFAULT_TEXT_COLORS = {
over: "#000", // over
out: "#000", // out
down: "#000", // down
disabled: "#999" // disabled
};
class RoundRectButton {
constructor(roundRectSetting) {
var outSprite = this.makeSprite(
roundRectSetting.width, roundRectSetting.height,
roundRectSetting.buttonColors.out
);
outSprite.x = 100;
outSprite.y = 100;
}
makeSprite(width, height, color) {
// create a new bitmap data object
var bmd = game.add.bitmapData(width, height);
bmd.ctx.beginPath();
bmd.ctx.rect(0, 0, width, height);
bmd.ctx.fillStyle = RectSetting.DEFAULT_BUTTON_COLORS.out;
bmd.ctx.fill();
return game.add.sprite(-1000, -1000, bmd);
}
}
/*
var DEFAULT_BUTTON_COLORS = [
"#fff", // over
"#aaf", // out
@@ -38,21 +106,19 @@ function RoundRectButton(roundRectSetting) {
// use the bitmap data as the texture for the sprite
/*
var newTextStyle = $.extend( {}, textStyleBasic);
newTextStyle.font = "bold 28px Arial";
// var newTextStyle = $.extend( {}, textStyleBasic);
// newTextStyle.font = "bold 28px Arial";
this.buttonText = game.add.text(0, 0, text, newTextStyle);
this.buttonText.addColor("#a0d", 0)
this.buttonText.anchor.setTo(0.5, 0.4);
// this.buttonText = game.add.text(0, 0, text, newTextStyle);
// this.buttonText.addColor("#a0d", 0)
// this.buttonText.anchor.setTo(0.5, 0.4);
this.startButton = game.add.button(x, y, 'button', callback, this, 2, 1, 0);
this.startButton.anchor.set(0.5);
this.startButton.inputEnabled = true;
this.startButton.input.priorityId = 1;
this.startButton.input.useHandCursor = true;
this.startButton.addChild(this.buttonText);
*/
// this.startButton = game.add.button(x, y, 'button', callback, this, 2, 1, 0);
// this.startButton.anchor.set(0.5);
// this.startButton.inputEnabled = true;
// this.startButton.input.priorityId = 1;
// this.startButton.input.useHandCursor = true;
// this.startButton.addChild(this.buttonText);
var overSprite = this.makeSprite(roundRectSetting.width, roundRectSetting.height, roundRectSetting.color[0]);
var outSprite = this.makeSprite(roundRectSetting.width, roundRectSetting.height, roundRectSetting.color[1]);
@@ -84,3 +150,4 @@ RoundRectButton.prototype.makeSprite = function(width, height, color) {
return game.add.sprite(300, 300, bmd);
}
*/
+38 -17
View File
@@ -1,38 +1,59 @@
/////////////////////////////
// Main game
var game = new Phaser.Game(1000, 800, Phaser.CANVAS, "Round rect image button test",
/**** Phaser3 *****
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'arcade',
arcade: {
gravity: { y: 200 }
}
},
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload() {
}
function create() {
console.log(game);
this.cameras.main.setBackgroundColor('#4d4d4d');
// game.stage.backgroundColor = '#4d4d4d';
// graphics = game.add.graphics(0, 0);
}
*/
var game = new Phaser.Game(1000, 800, Phaser.CANVAS, "RoundRectButton",
{preload:preload, create:create, update:update, render:render});
function preload() {
game.load.image('phaser', './image/phaser.png');
// game.load.image('phaser', '../../resources/image/phaser.png');
// game.load.spritesheet('button', './image/button_basic.png', 200, 100);
}
function create() {
var i = game.add.image(game.world.centerX, game.world.centerY + 70, 'phaser');
i.anchor.set(0.5);
// var i = game.add.image(game.world.centerX, game.world.centerY + 70, 'phaser');
// i.anchor.set(0.5);
game.stage.backgroundColor = '#4d4d4d';
graphics = game.add.graphics(0, 0);
new RoundRectButton(new RectSetting(200, 100));
let button = new RoundRectButton(new RectSetting(200, 100));
console.log(button);
}
function update() {
}
function render() {
// showDebugMessage();
}
/////////////////////////////
// custom methods
function showDebugMessage() {
// game.debug.text( "This is debug text 한글 " + spriteMushroom.x + ", " + spriteMushroom.y + ", highscore : " + highScore, 100, 380 );
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB