lifesuxtr

Members
  • Content count

    21
  • Joined

  • Last visited

  1. How to load sprites on phaser based on database data

    Hello.Rıght now i dont have any states.game just starts immediately.Lets say that i want to start the game from subscribe.If i put all my functions into lets say a start state how do i reach game variable from that state ?(because i decleared it in ionViewDidLoad) right now my preload create update functions are right under ionViewDidLoad.I mean ionViewDidLoad(){ //this.game decleration } preload(){ } create(){ } update(){ } //so if i launch the page game immediately loads and starts. //If i try to move all above code to a state structure to call it from ionviewDidloads subscribe callback like: start = Object.assign(new Phaser.State(), { preload: function () { //how do i reach this.game from here ???? }, create: function () {} });
  2. How to load sprites on phaser based on database data

    Thanks for the answer i guess using the promises is the best solution.I was reading about it and trying but couldnt make it work.can you give an example
  3. Hi thanks for the answer but i cant use that let gameOverState = { preload: function () {}, create: function () { // … onInputDown.add -> // game.state.start('game'); } }; structure in my typescript file.It says constructor method... needed for it.I am trying to create states in 1 file.
  4. How to attach text on enemies

    Thanks... it worked
  5. How to attach text on enemies

    I tried that too this is the result:
  6. How to attach text on enemies

    I tried something similar to this i cant reach coordinates Cannot set property x undefined error
  7. How to attach text on enemies

    this.zombies = this.game.add.group(); this.zombies.enableBody=true; for (var i = 0; i < 5; i++) { var zombie = this.zombies.create(this.game.world.randomX, this.game.world.randomY, 'zombie'); zombie.health=5; this.zombieHealthText=this.game.add.text(zombie.x, zombie.y, "5", { fontSize: '16px', fill: '#000' }); } I am trying to add text on moving enemies.This code creates text on their initial point.What should i write inside update function to make them stick to zombies while they are moving ?
  8. remove

    i solved it
  9. How to load sprites on phaser based on database data

    I know that.I just need to make preload function wait for db data to come.It works way to fast so i cant display db data.Somehow i need to create a state and call that state from inside subscribe
  10. I am trying to create a gamestate in phaser. The problem is typescript is not allowing me to do it by this Iam triying to put all functions into 1 state then call that state. let gameState = { //preload update create functions here }; After initializing game this.game.state.add('game', gameState); Then call state in subscribe this.game.state.start('gameState'); The problem is typescript doesnt let me to create a state with above let gameState structure.It says Unexpected token. A constructor, method, accessor, or property was expected.
  11. Problem with Installing Plugin

    I am trying to install this plugin : https://github.com/matthiaswh/phaser-health-meter I put js file into this directory: Included it as : import {HealthMeter} from "phaser-ce/src/plugins/healthMeter" And as mentioned in documentation: this.player.health=50; this.player.maxHealth = 100; this.playerHealthMeter = this.game.add.plugin(Phaser.Plugin.HealthMeter); this.playerHealthMeter.bar( this.player, {x: 20, y: 100, width: 100, height: 20} ); This is the error: I guess im putting js file to wrong directory
  12. problem with .damage oneshots

    I know its missleaing must be bullet and zombie
  13. How to load sprites on phaser based on database data

    Hi thanks for the answer.I am triying to put all functions into 1 state and call that state from inside subscribe. let gameState = { //preload update create functions here }; After initializing game this.game.state.add('game', gameState); Then call state in subscribe this.game.state.start('gameState'); The problem is typescript doesnt let me to create a state with above let gameState structure.It says Unexpected token. A constructor, method, accessor, or property was expected.
  14. problem with .damage oneshots

    I figured out the problem completely.The external library im using for healtbars is breaking the player health or zombie health. import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; import * as Phaser from "phaser-ce"; import { AngularFireAuth } from 'angularfire2/auth'; import { AngularFireDatabase } from 'angularfire2/database'; import { Observable } from 'rxjs/Observable'; import { HealthBar } from 'rxjs/healthBar'; /** * Generated class for the ZombiePage page. * * See https://ionicframework.com/docs/components/#navigation for more info on * Ionic pages and navigation. */ @IonicPage() @Component({ selector: 'page-zombie', templateUrl: 'zombie.html', }) export class ZombiePage { game:any; spacefield:any; map:any; layer:any; cursors:any; player:any; zombies:any; laser:any; profileData: Observable<any[]> | any; avatar:any; constructor(private fire: AngularFireAuth, private db: AngularFireDatabase,public navCtrl: NavController, public navParams: NavParams) { } ionViewDidLoad() { console.log('ionViewDidLoad ZombiePage'); this.game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, 'game', { preload: this.preload.bind(this), create: this.create.bind(this),update:this.update.bind(this),render:this.render.bind(this) }); console.log(window.innerHeight); this.profileData = this.fire.authState.switchMap(auth => this.db.object(`profile/${auth.uid}`).valueChanges()); this.profileData.subscribe(profile =>{ this.avatar = profile.avatar; console.log(this.avatar); }); } preload(){ console.log(this.avatar) this.game.load.tilemap('map', 'assets/zombie.csv', null, Phaser.Tilemap.CSV); this.game.load.image('player', 'assets/petyr.png'); this.game.load.image('tiles', 'assets/zombie.png'); this.game.load.image('zombie','assets/actualzombie.png'); this.game.load.image('laser', 'assets/laser.png'); } create(){ this.map = this.game.add.tilemap('map', 64, 64); // Now add in the tileset this.map.addTilesetImage('tiles'); // Create our layer this.layer = this.map.createLayer(0); // Resize the world this.layer.resizeWorld(); // Allow cursors to scroll around the map this.cursors = this.game.input.keyboard.createCursorKeys(); this.player = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY,'player'); this.game.physics.enable(this.player,Phaser.Physics.ARCADE); this.player.scale.setTo(0.20,0.20) this.player.health=500; //new HealthBar(this.game, this.player, 75, 10, 25, -10, '#FF0000', '#00FF00'); this.game.camera.follow(this.player); // Creates 30 bullets, using the 'bullet' graphic this.laser = this.game.add.weapon(100, 'laser'); // The bullet will be automatically killed when it leaves the world bounds this.laser.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; // The speed at which the bullet is fired this.laser.bulletSpeed = 300; // Speed-up the rate of fire, allowing them to shoot 1 bullet every 60ms this.laser.fireRate = 400; this.laser.trackSprite(this.player, 20, 20, false); this.zombies = this.game.add.group(); this.zombies.enableBody=true; for (var i = 0; i < 30; i++) { var zombie = this.zombies.create(this.game.world.randomX, this.game.world.randomY, 'zombie'); zombie.health=5; let zombieHealthBar = new HealthBar(this.game, zombie, 25, 10, -20, 0, '#FF0000', '#00FF00'); } } update(){ console.log(this.player.health); this.player.body.velocity.x = 0 this.player.body.velocity.y = 0 if (this.cursors.left.isDown) { this.player.body.velocity.x =-150; } else if (this.cursors.right.isDown) { this.player.body.velocity.x =150; } if (this.cursors.up.isDown) { this.player.body.velocity.y =-150; } else if (this.cursors.down.isDown) { this.player.body.velocity.y=150; } this.zombies.forEach(function(enemy){ enemy.rotation = this.game.physics.arcade.angleBetween(enemy, this.player); this.game.physics.arcade.velocityFromAngle(enemy.angle, 150, enemy.body.velocity); //this.game.physics.arcade.moveToObject(enemy,this.player,250); },this); if (this.game.input.activePointer.isDown) { this.laser.fireAtPointer(this.game.input.activePointer); } this.game.physics.arcade.overlap(this.laser.bullets, this.zombies, this.hitEnemy, null, this); this.game.physics.arcade.overlap(this.player, this.zombies, this.playerdmg, null, this); } playerdmg(player,zombies){ player.damage(1); // not working. } hitEnemy(bullets,zombies){ zombies.damage(1); // this is not working console.log(zombies.health); bullets.kill(); } render(){ } } This one is working.If i uncomment HealthBar codes it doesnt work.it just resets player and zombie health to 0.I couldnt figure out why. this is the plugin im using:(healhBar.js) "use strict"; var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; var HealthBar = (function (_super) { __extends(HealthBar, _super); function HealthBar(game, spriteToAttach, width, height, _xOffset, _yOffset, bgColor, fgColor) { if (_xOffset === void 0) { _xOffset = 0; } if (_yOffset === void 0) { _yOffset = 0; } if (bgColor === void 0) { bgColor = "#DD1111"; } if (fgColor === void 0) { fgColor = "#11DD11"; } _super.call(this, game, spriteToAttach.body.position.x + _xOffset, spriteToAttach.body.position.y + _yOffset); this.spriteToAttach = spriteToAttach; this.width = width; this.height = height; this._xOffset = _xOffset; this._yOffset = _yOffset; this.bgColor = bgColor; this.fgColor = fgColor; //Draw bar background this.bmdBg = game.add.bitmapData(width, height); this.bmdBg.ctx.fillStyle = this.bgColor; this.bmdBg.ctx.fillRect(0, 0, width, height); this.bgSprite = game.add.sprite(this.x, this.y, this.bmdBg); this.bgSprite.anchor.set(0.5); //Draw bar foreground this.bmdFg = game.add.bitmapData(width, height); this.bmdFg.ctx.fillStyle = this.fgColor; this.bmdFg.ctx.fillRect(0, 0, width, height); this.fgSprite = game.add.sprite(this.x, this.y, this.bmdFg); this.fgSprite.anchor.set(0.5); this.game.world.add(this); // triggers the update function } HealthBar.prototype.update = function () { //Redraw health this.bmdFg.clear(); this.bmdFg.ctx.fillRect(0, 0, (this.width / 100) * this.spriteToAttach.health, this.height); //Health bar follow sprite this.bgSprite.position.x = this.spriteToAttach.position.x + this.xOffset; this.bgSprite.position.y = this.spriteToAttach.position.y + this.yOffset; this.fgSprite.position.x = this.spriteToAttach.position.x + this.xOffset; this.fgSprite.position.y = this.spriteToAttach.position.y + this.yOffset; //Delete on destroy if (this.spriteToAttach.health = 0) { this.bmdFg.destroy(); this.bmdBg.destroy(); this.bgSprite.destroy(); this.fgSprite.destroy(); this.destroy(); } }; Object.defineProperty(HealthBar.prototype, "xOffset", { get: function () { return this._xOffset; }, set: function (xOff) { this._xOffset = xOff; }, enumerable: true, configurable: true }); Object.defineProperty(HealthBar.prototype, "yOffset", { get: function () { return this._yOffset; }, set: function (yOff) { this._yOffset = yOff; }, enumerable: true, configurable: true }); return HealthBar; }(Phaser.Sprite)); exports.HealthBar = HealthBar;