Add: Chocoball onClick event handler
This commit is contained in:
@@ -1,12 +1,24 @@
|
|||||||
// Chocoball.prototype = Object.create(Phaser.Sprite.prototype);
|
// Chocoball.prototype = Object.create(Phaser.Sprite.prototype);
|
||||||
// Chocoball.constructor = Chocoball;
|
Chocoball.constructor = Chocoball;
|
||||||
|
|
||||||
function Chocoball(index) {
|
|
||||||
this.isActivated = false;
|
|
||||||
|
|
||||||
|
function Chocoball(index, onClickHandler) {
|
||||||
|
this.index = index;
|
||||||
this.row = Math.floor(index / 5);
|
this.row = Math.floor(index / 5);
|
||||||
this.col = 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 x = 200 + this.col * 100;
|
||||||
var y = 200 + this.row * 100;
|
var y = 200 + this.row * 100;
|
||||||
this.body = game.add.sprite(x, y, 'choco_body');
|
this.body = game.add.sprite(x, y, 'choco_body');
|
||||||
@@ -14,19 +26,16 @@ function Chocoball(index) {
|
|||||||
this.body.anchor.set(0.5);
|
this.body.anchor.set(0.5);
|
||||||
this.body.tint = 0xff0000;
|
this.body.tint = 0xff0000;
|
||||||
|
|
||||||
this.gloss = game.add.sprite(x, y, 'choco_gloss');
|
this.body.inputEnabled = true;
|
||||||
this.gloss.scale.set(1);
|
this.body.events.onInputDown.add(this.onClick, this);
|
||||||
this.gloss.anchor.set(0.5);
|
|
||||||
|
|
||||||
this.number = this.makeNumber("50");
|
this.number = this.makeNumber("50");
|
||||||
this.body.addChild(this.number);
|
this.body.addChild(this.number);
|
||||||
|
|
||||||
// game.add.existing(this);
|
this.gloss = game.add.sprite(x, y, 'choco_gloss');
|
||||||
// game.physics.arcade.enable(this);
|
this.gloss.scale.set(1);
|
||||||
|
this.gloss.anchor.set(0.5);
|
||||||
// this.halfWidth = this.width / 2;
|
|
||||||
|
|
||||||
this.setActive(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Chocoball.prototype.makeNumber = function(textContent) {
|
Chocoball.prototype.makeNumber = function(textContent) {
|
||||||
@@ -49,6 +58,12 @@ Chocoball.prototype.setActive = function(isActivated) {
|
|||||||
this.isActivated = isActivated;
|
this.isActivated = isActivated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Chocoball.prototype.onClick = function() {
|
||||||
|
if(typeof this.onClickHandler !== "undefined")
|
||||||
|
this.onClickHandler(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Chocoball.loadResources = function() {
|
Chocoball.loadResources = function() {
|
||||||
game.load.image('choco_gloss', '../../../resources/image/object/one_to_fifty/choco_gloss.png');
|
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');
|
game.load.image('choco_body', '../../../resources/image/object/one_to_fifty/choco_body.png');
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ var Game = {
|
|||||||
this.dbConnectManager = new DBConnectManager();
|
this.dbConnectManager = new DBConnectManager();
|
||||||
sessionStorageManager.setRecord(0);
|
sessionStorageManager.setRecord(0);
|
||||||
|
|
||||||
this.game.stage.backgroundColor = "#000000"; // '#4d4d4d';
|
|
||||||
|
|
||||||
sessionStorageManager.setIsNewAppHighestRecord(false);
|
sessionStorageManager.setIsNewAppHighestRecord(false);
|
||||||
|
|
||||||
var experienceAppTimer = new ExperienceAppTimer();
|
var experienceAppTimer = new ExperienceAppTimer();
|
||||||
@@ -22,28 +20,19 @@ var Game = {
|
|||||||
"1 to 50" // callerClassName
|
"1 to 50" // callerClassName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// game stage
|
||||||
|
game.stage.backgroundColor = '#4d4d4d';
|
||||||
|
|
||||||
// top ui
|
// top ui
|
||||||
var screenTopUI = new ScreenTopUI();
|
var screenTopUI = new ScreenTopUI();
|
||||||
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
|
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
|
||||||
screenTopUI.makeFullScreenButton();
|
screenTopUI.makeFullScreenButton();
|
||||||
|
|
||||||
this.stopWatch = new StopWatch(game);
|
this.stopWatch = new StopWatch(game);
|
||||||
|
|
||||||
|
|
||||||
this.chocoballs = new Array();
|
// init game elements
|
||||||
for(var i = 0; i < 25; i++) {
|
|
||||||
var chocoball = new Chocoball(i);
|
|
||||||
chocoball.setNumber(i);
|
|
||||||
this.chocoballs.push(chocoball);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.initVariables();
|
this.initVariables();
|
||||||
|
|
||||||
// game stage
|
|
||||||
game.stage.backgroundColor = '#4d4d4d';
|
|
||||||
graphics = game.add.graphics(0, 0);
|
|
||||||
|
|
||||||
|
|
||||||
// bottom ui
|
// bottom ui
|
||||||
var screenBottomUI = new ScreenBottomUI();
|
var screenBottomUI = new ScreenBottomUI();
|
||||||
@@ -57,6 +46,12 @@ var Game = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
initVariables: function() {
|
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() {
|
back: function() {
|
||||||
@@ -65,6 +60,11 @@ var Game = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
onClickChocoball: function(chocoball) {
|
||||||
|
console.log(chocoball.index);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
startGame: function() {
|
startGame: function() {
|
||||||
this.stopWatch.start();
|
this.stopWatch.start();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user