Hello,
In the game I'm currently devving i'm trying to flip cards up/down in a stock.
Initialization works fine, it reads the state the card is in and updates the image accordingly:
But things get tricky when I try to refresh the img through notifications:
I couldn't find adequate documentation to change style "on the spot", so the only solution I found was to remove the card from the stock face up/down and add it in the stock again face down/up. The problem is that they are added automatically at the end of the stock and not where they were before. When I refresh the page then the cards are correctly displayed at the right position in the right state :
This is not ideal at all for the mechanism of my game as this part is supposed to be some kind of memory game.
I would take gladly any advice on that, thank you so much!
In the game I'm currently devving i'm trying to flip cards up/down in a stock.
Initialization works fine, it reads the state the card is in and updates the image accordingly:
Code: Select all
// Create cards types:
for (var color = 1; color <= 4; color++) {
// Build card type id
value = 1;
var card_type_id = this.getObjectCardUniqueId(color, value);
var path_img = 'img/objects.jpg';
this.tableHand.addItemType(card_type_id, 1, g_gamethemeurl + path_img, color-1);
// Putting the same value here, "1" so that the stock sort them by ID and not by value in the stock.
// -1 is here so that the numbers in the db correspond to the card number displayed.
}
for (var color = 1; color <= 4; color++) {
// Build card type id
value = 1;
var card_type_id = this.getObjectCardUniqueId(color, value) + 8;
var path_img = 'img/backcard.jpg';
this.tableHand.addItemType(card_type_id, 1, g_gamethemeurl + path_img, color-1);
}
// Cards in center of the table hand
var objectcard_table = gamedatas.objectcard_states;
for ( var i in this.gamedatas.table) {
var card = this.gamedatas.table[i];
var color = card.type;
var value = card.type_arg;
var objectcard_state = objectcard_table[card.id].card_state;
if (objectcard_state == 0){
this.tableHand.addToStockWithId(this.getObjectCardUniqueId(color, value)+8, card.id);
}
if (objectcard_state == 1){
this.tableHand.addToStockWithId(this.getObjectCardUniqueId(color, value), card.id);
}
}I couldn't find adequate documentation to change style "on the spot", so the only solution I found was to remove the card from the stock face up/down and add it in the stock again face down/up. The problem is that they are added automatically at the end of the stock and not where they were before. When I refresh the page then the cards are correctly displayed at the right position in the right state :
Code: Select all
notif_flipObjectCard : function(notif) {
// Flip cards on the table
console.log('Not implemented yet');
if(notif.args.objectcard_state == 0) //Face down
{
this.tableHand.removeFromStockById(notif.args.objectcard_id);
this.tableHand.addToStockWithId(this.getObjectCardUniqueId(notif.args.objectcard_color, 1), notif.args.objectcard_id); //We add it face up
}
if(notif.args.objectcard_state == 1) //Face up
{
this.tableHand.removeFromStockById(notif.args.objectcard_id);
this.tableHand.addToStockWithId(this.getObjectCardUniqueId(notif.args.objectcard_color, 1) + 8, notif.args.objectcard_id); // We add it face down
}
// THIS DOESNT WORK !!!
// as the cards are added to the end like a pile.
},I would take gladly any advice on that, thank you so much!