Add: Chocoball onClick event handler

This commit is contained in:
2019-05-10 07:49:04 +09:00
parent 413400dfda
commit c87308f604
2 changed files with 43 additions and 28 deletions
+28 -13
View File
@@ -1,12 +1,24 @@
// Chocoball.prototype = Object.create(Phaser.Sprite.prototype);
// Chocoball.constructor = Chocoball;
function Chocoball(index) {
this.isActivated = false;
Chocoball.constructor = Chocoball;
function Chocoball(index, onClickHandler) {
this.index = index;
this.row = Math.floor(index / 5);
this.col = index % 5;
this.onClickHandler = onClickHandler;
this.initVariables();
this.drawChocoball();
this.setActive(true);
}
Chocoball.prototype.initVariables = function(textContent) {
this.isActivated = false;
}
Chocoball.prototype.drawChocoball = function() {
var x = 200 + this.col * 100;
var y = 200 + this.row * 100;
this.body = game.add.sprite(x, y, 'choco_body');
@@ -14,19 +26,16 @@ function Chocoball(index) {
this.body.anchor.set(0.5);
this.body.tint = 0xff0000;
this.gloss = game.add.sprite(x, y, 'choco_gloss');
this.gloss.scale.set(1);
this.gloss.anchor.set(0.5);
this.body.inputEnabled = true;
this.body.events.onInputDown.add(this.onClick, this);
this.number = this.makeNumber("50");
this.body.addChild(this.number);
// game.add.existing(this);
// game.physics.arcade.enable(this);
// this.halfWidth = this.width / 2;
this.setActive(true);
this.gloss = game.add.sprite(x, y, 'choco_gloss');
this.gloss.scale.set(1);
this.gloss.anchor.set(0.5);
}
Chocoball.prototype.makeNumber = function(textContent) {
@@ -49,6 +58,12 @@ Chocoball.prototype.setActive = function(isActivated) {
this.isActivated = isActivated;
}
Chocoball.prototype.onClick = function() {
if(typeof this.onClickHandler !== "undefined")
this.onClickHandler(this);
}
Chocoball.loadResources = function() {
game.load.image('choco_gloss', '../../../resources/image/object/one_to_fifty/choco_gloss.png');
game.load.image('choco_body', '../../../resources/image/object/one_to_fifty/choco_body.png');
+15 -15
View File
@@ -4,8 +4,6 @@ var Game = {
this.dbConnectManager = new DBConnectManager();
sessionStorageManager.setRecord(0);
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
sessionStorageManager.setIsNewAppHighestRecord(false);
var experienceAppTimer = new ExperienceAppTimer();
@@ -22,28 +20,19 @@ var Game = {
"1 to 50" // callerClassName
);
// game stage
game.stage.backgroundColor = '#4d4d4d';
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
screenTopUI.makeFullScreenButton();
this.stopWatch = new StopWatch(game);
this.chocoballs = new Array();
for(var i = 0; i < 25; i++) {
var chocoball = new Chocoball(i);
chocoball.setNumber(i);
this.chocoballs.push(chocoball);
}
// init game elements
this.initVariables();
// game stage
game.stage.backgroundColor = '#4d4d4d';
graphics = game.add.graphics(0, 0);
// bottom ui
var screenBottomUI = new ScreenBottomUI();
@@ -57,6 +46,12 @@ var Game = {
},
initVariables: function() {
this.chocoballs = new Array();
for(var i = 0; i < 25; i++) {
var chocoball = new Chocoball(i, this.onClickChocoball);
chocoball.setNumber(i);
this.chocoballs.push(chocoball);
}
},
back: function() {
@@ -65,6 +60,11 @@ var Game = {
},
onClickChocoball: function(chocoball) {
console.log(chocoball.index);
},
startGame: function() {
this.stopWatch.start();
},