Fix: move round_rect_button.js to src/lib/js
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 4.9 KiB |
@@ -1,19 +0,0 @@
|
||||
<!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>
|
||||
@@ -1,47 +0,0 @@
|
||||
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.
|
Before Width: | Height: | Size: 39 KiB |
@@ -19,13 +19,13 @@
|
||||
<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="../../src/game/lib/js/round_rect_button.js"></script>
|
||||
<script src="./round_rect_button_main.js"></script>
|
||||
</head>
|
||||
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
class RoundRectButtonSetting {
|
||||
|
||||
constructor(width, height, roundAmount) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.roundAmount = 0;
|
||||
if(typeof roundAmount === "undefined") {
|
||||
let shorterSide = width > height ? height : width;
|
||||
this.roundAmount = shorterSide * 0.1;
|
||||
} else {
|
||||
this.roundAmount = roundAmount;
|
||||
}
|
||||
|
||||
this.buttonColors = RoundRectButtonSetting.DEFAULT_BUTTON_COLORS;
|
||||
this.textColors = RoundRectButtonSetting.DEFAULT_TEXT_COLORS;
|
||||
this.fontStyle = RoundRectButtonSetting.DEFAULT_TEXT_FONT;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
RoundRectButtonSetting.DEFAULT_BUTTON_COLORS = {
|
||||
out: 0xffffff,
|
||||
over: 0xddffdd,
|
||||
down: 0xaaffaa,
|
||||
disabled: 0x333333
|
||||
};
|
||||
|
||||
RoundRectButtonSetting.DEFAULT_TEXT_COLORS = {
|
||||
out: "#000",
|
||||
over: "#333",
|
||||
down: "#666",
|
||||
disabled: "#999"
|
||||
};
|
||||
|
||||
RoundRectButtonSetting.DEFAULT_TEXT_FONT = {
|
||||
font: "30px Arial",
|
||||
align: "center",
|
||||
fill: "#fff"
|
||||
};
|
||||
|
||||
RoundRectButtonSetting.DEFAULT_LINE_SPACING = -10; // pixels
|
||||
|
||||
|
||||
|
||||
class RoundRectButton {
|
||||
constructor(roundRectSetting, buttonText, clickEvent) {
|
||||
this.setting = roundRectSetting;
|
||||
this.clickEvent = clickEvent;
|
||||
|
||||
this.button = this.makeSprite();
|
||||
this.text = this.makeText(buttonText);
|
||||
|
||||
this.button.addChild(this.text);
|
||||
this.button.anchor.setTo(0.5, 0.5);
|
||||
|
||||
this.inputEnabled = true;
|
||||
this.setEventMethod();
|
||||
|
||||
this.mouseOut();
|
||||
}
|
||||
|
||||
setEventMethod() {
|
||||
this.button.events.onInputOver.add(function() {
|
||||
this.mouseOver();
|
||||
}, this);
|
||||
|
||||
this.button.events.onInputOut.add(function() {
|
||||
this.mouseOut();
|
||||
}, this);
|
||||
|
||||
this.button.events.onInputDown.add(function() {
|
||||
this.mouseDown();
|
||||
|
||||
if(this.clickEvent) {
|
||||
this.clickEvent();
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.button.events.onInputUp.add(function() {
|
||||
this.mouseOver();
|
||||
}, this);
|
||||
}
|
||||
|
||||
makeSprite() {
|
||||
let btnTexture = new Phaser.Graphics()
|
||||
.beginFill(RoundRectButton.white)
|
||||
.drawRoundedRect(0, 0, this.setting.width, this.setting.height, this.setting.roundAmount)
|
||||
.endFill()
|
||||
.generateTexture();
|
||||
|
||||
return game.add.sprite(0, 0, btnTexture);
|
||||
}
|
||||
|
||||
makeText(textContent) {
|
||||
let btnText = game.add.text(0, 0, textContent, this.setting.fontStyle);
|
||||
btnText.anchor.setTo(0.5);
|
||||
btnText.lineSpacing = RoundRectButtonSetting.DEFAULT_LINE_SPACING;
|
||||
|
||||
return btnText;
|
||||
}
|
||||
|
||||
|
||||
mouseOut() {
|
||||
this.button.tint = this.setting.buttonColors.out;
|
||||
this.text.fill = this.setting.textColors.out;
|
||||
}
|
||||
|
||||
mouseOver() {
|
||||
this.button.tint = this.setting.buttonColors.over;
|
||||
this.text.fill = this.setting.textColors.over;
|
||||
}
|
||||
|
||||
mouseDown() {
|
||||
this.button.tint = this.setting.buttonColors.down;
|
||||
this.text.fill = this.setting.textColors.down;
|
||||
}
|
||||
|
||||
buttonDisabled() {
|
||||
this.button.tint = this.setting.buttonColors.disabled;
|
||||
this.text.fill = this.setting.textColors.disabled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
move(x, y) {
|
||||
this.button.x = x;
|
||||
this.button.y = y;
|
||||
}
|
||||
|
||||
get inputEnabled() {
|
||||
return this.button.inputEnabled;
|
||||
}
|
||||
|
||||
set inputEnabled(isEnabled) {
|
||||
this.button.inputEnabled = isEnabled;
|
||||
|
||||
if(isEnabled === true) {
|
||||
this.mouseOut();
|
||||
} else {
|
||||
this.buttonDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
set lineSpacing(spacingInPixels) {
|
||||
this.text.lineSpacing = spacingInPixels;
|
||||
}
|
||||
}
|
||||
|
||||
RoundRectButton.defaultRoundAmount = 10;
|
||||
RoundRectButton.white = 0xffffff;
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.7 KiB |
Reference in New Issue
Block a user