Regentix

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. Hello, i am new to phaser and wondering why the event i bound to my sprite doesn't work. I am trying to make it so when you tap the sprite on mobile/desktop, it has an upwards velocity, but this is not working. I am following the docs/examples on how to do so. This is my code: var game = new Phaser.Game('100', '100', Phaser.AUTO, '', {preload: preload, create: create, update: update}); var ball, counterText; function preload() { game.load.image('ball', 'assets/ball.png'); } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#F4F4F4'; ball = game.add.sprite(game.world.width / 2 - 50 ,game.world.height / 2 - 100,'ball'); game.physics.arcade.enable(ball); ball.body.bounce.y = 0.9; ball.body.gravity.y = 0; ball.body.collideWorldBounds = true; ball.inputEnabled = true; ball.events.onInputDown.add(onBallTap, this); counterText = game.add.text(game.world.centerX, 40, 'TEST', {fontSize: '40px', fill: '#fff'}); counterText.anchor.setTo(0.5); } function update() { if (game.input.pointer1.isDown) { ball.body.gravity.y = 3000; } if (ball.body.onFloor()) { counterText.addColor(randomHexColor(), 0); } } function randomHexColor() { color = Math.random() * 0xffffff; hexColor = '#' + parseInt(color).toString(16); return hexColor; } function onBallTap() { ball.body.velocity.y = -1300; }
  2. Hello, i am new to using Phaser, and i would love to know if i am able to use DOM elements within my Phaser stage (canvas). I have a div which is styled to look like a ball and i would like to use this ball in the phaser game to physicly bounce on any of the ledges i will define in the future. My question: can i use this DOM element to do so? Or should i use a sprite/image? Because whenever the ball hits any of the ledges, i want it to change color. (I know this is possible with sprites and sprite recoloring) Greetings, Regentix