megamaster

Members
  • Content Count

    11
  • Joined

  • Last visited

About megamaster

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thank you! I will check it out. I'm looking for a host that can handle many small html5 packages instead of just one big game. Would Heroku work well for this?
  2. Can you give me a tutorial on this? I'm thinking about going with Heroku
  3. Right, I'm still trying to figure everything out. I had to program in matlab for a college class, but javascript has many of its own commands as well. Thanks for letting me know about ES6 let! I think that has done the trick
  4. I hope I'm not breaking any rules by bumping this thread. I'm still looking for a reason why the code isn't working though. Thanks
  5. Thanks for the help s6reinan. I made some tweaks to your advice and came up with the following code: var card1 = 1 var card2 = 2 var card3 = 3 var cardarray = [card1,card2,card3] function create() { //creating array cardarray = shuffle(cardarray); cardarray = cardarray.splice(0,5); var card = []; for(var i = 0; i < cardarray.length; i++) { card[i] = cardarray[i]; //console.log(cardarray[0]) //console.log(chip[0]) card[i] = game.add.sprite(0, 0, 'card' + card[i]); card[i].inputEnabled = true; card[i].events.onInputDown.add( function() { cardEffects(cardarray[i]); }, this); } function cardEffects(index) { if (index==1) { //some operation } if (index==2) { //some operation } if (index==3) { //some operation } else if () { } } I am still having trouble with the on click events. Each rendered image is clickable but the parameter of the index is not sent to the cardEffects function. So, when I click on the sprite nothing happens even though the parameter must make one of the statements true. Do you know why this is?
  6. Thanks for the quick response. However, I'm still not sure if I understand how the higher functions work. What I want are defined function names that can be called based on the variable that is selected from an array. The problem is my array is shuffled, so cardarray[0] does not always correspond to the function cardEffects1 What you have suggested works, but I don't see how to make "function(index)" and "cardEffects(index)" refer to the actual variable I am working with. Can you explain your call method to me? (I'm still a programming beginner) I thought the simplest way to do this would be to pass var card1, which has a string value of cardEffects1, for the function name in the onInputDown.add. Unfortunately that doesn't work because it doesn't recognize it as a function name. var cardarray = [card1,card2,card3]
  7. So while working on a card game I ran into an issue calling a function for a specific card. I have an array that is randomly shuffled. From that array I want to call the variable and the appropriate sprite for it. In addition, I want to call a function when that specific card is clicked on. This is what I have so far: function create() { //creating array cardarray = shuffle(cardarray); cardarray[0] = game.add.sprite(80, 60, 'card'+'cardarray[0]'); cardarray[0].inputEnabled = true; cardarray[0].events.onInputDown.add(toString('cardarray[0]'+'effects', this); } function card1effects() { //whatever function does } I don't know the proper syntax for calling a function with a variable that depends on an array. Thanks
  8. So I figured out the issue. This: player1.onInputDown.add(decreaseHealth, this); Should be this: player1.events.onInputDown.add(decreaseHealth, this); Thanks for reminding about the console. It helped me spot a few other errors as well
  9. So here's the error I got using google's console: Uncaught TypeError: Cannot read property 'add' of undefined at Object.create (part2.html:41) at c.StateManager.loadComplete (phaser.min.js:8) at c.SignalBinding.execute (phaser.min.js:8) at c.Signal.dispatch (phaser.min.js:8) at c.Loader.nextFile (phaser.min.js:17) at c.Loader.fileComplete (phaser.min.js:17) at HTMLImageElement.a.data.onload (phaser.min.js:17) any suggestions?
  10. Thanks for the feedback! I've got the font working now, but I'm still having a bit of trouble with the on-click event. I made the health a separate function but it is still not working. Any suggestions?
  11. Hi fellow phasers, I am having difficulty making a single event occur when pointer input is pressed down. I've searched the forums for a solution but nothing seems to be working for me. The recommendation that I have seen is this code: game.input.onDown.add(doSomething, this); function doSomething() { // will only ever be called once, when the the input is down } I simply want to reduce health of a character when the sprite is clicked. This is what I have written: var player1; var health1 = 100; function create() { player1 = game.add.sprite(44, 70, 'stand'); health1Text = game.add.text(2, 10, 'health: 100', { fontSize: '10px Arial', fill: '#fff' }); player1.inputEnabled = true; player1.onDown.add(update, this); function update() { health1 += -10; health1Text.text = 'health: ' + health1; What happens when I run it is that the health constantly decreases without any input pressed. I have tried different input methods as well, but they won't reduce the health by a factor of 10 at a time. Also the font size is not working for me either. Thanks for any and all help!