Search the Community

Showing results for tags 'extending'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 5 results

  1. I'm stuck with loading my meshes. I'm new to all the 3D and modelling so any thoughts are highly appreciated. Basically I want to extends Babylons default Mesh class called BaseMesh and add a 'load' function to it to get rid of clutter in my scene code. I'm extending this BaseMesh class for each model I have. My BaseMesh class: (Note that all code examples are written in TypeScript) // BaseMesh.ts class BaseMesh /* extends BABLYON.Mesh */ { public readonly BASE_URL: string; // I want these to be static public readonly MODEL_URL: string; // I want these to be static public readonly NAME: string; // I want these to be static public body; /* constructor( scene ) { // I don't know what to do here super( this.NAME //name scene // scene null // parent ? // source ); } */ public load( assetsManager: BABYLON.AssetsManager ) { return assetsManager.addMeshTask( this.NAME + ' task', // name "", this.BASE_URL, this.MODEL_URL ); } public onLoaded( results ) { // I don't know what to do here this.body = results.loadedMeshes[0]; } public update(): void {} }; A model class would looks like this: // Robot.ts class Robot extends BaseMesh { public readonly BASE_URL: string = '/models/'; public readonly MODEL_URL: string = 'robot.babylon'; public readonly NAME: string = 'robotMesh'; public update(): void { this.body.rotation.y += 0.03; } } In my code above I store the loadedMesh from the AssetsManager into this.body. But here is question 1: why is my model already showing on the scene when the meshtask has run? I'm only loading a mesh, I've not put anything about putting it on the scene. Question 2: How do I extend my BaseMesh class from BABLYON.Mesh so that the result (loadedMeshes) of my load function is "the mesh itself" (instead of an attribute this.body). For example this would mean I could change my update function to 'this.rotation.y += 0.03;' and just generally makes more sense. Question 3: I'm really confused about the relationship between my "code" and my "model/.babylon files". Is there any good documentation/tutorials about this? These questions range from: - when is it healthy to split different parts of a model in different files - do I apply textures in my code or do I do that in my .babylon file - do I apply animations in my blender file or do I code them - ... This was a pain to type, if you have any questions please do ask Thank you in advance!
  2. Hi everyone, I'm extending an sprite with the following code: Monster = function (game, x, y) { Phaser.Sprite.call(this, game, x, y, 'monster01'); this.game.physics.enable(this, Phaser.Physics.ARCADE); //graphics this.anchor.set(.5, 1); this.body.setSize(290, 670, 330, 110); }; Monster.prototype = Object.create(Phaser.Sprite.prototype); Monster.prototype.constructor = Monster; Monster.prototype.update = function() { //input if(this.game.input.activePointer.isDown) { if(Phaser.Rectangle.contains(this.body, this.game.input.worldX, this.game.input.worldY)) { BasicGame.PPGPlayer.clickOnMonster(this); } } }; I'm adding this sprite to the main state using: this.monster = new Monster(this.game, this.game.world.width * .5 + 400, 990); this.add.existing(this.monster); Then, I'm killing it with this.monster.kill() and the sprite disappears but the body is still on the state. If I render the body I can still see it: render: function (){ this.game.debug.body(this.monster); }, Why is this happening and what is the best way to solve it? Thanks!
  3. Hi! I'm new to Phaser and have had great fun learning the engine. I recently started separating the code for my game into prefab files by extending Phaser.Sprite but I have run in to trouble. When Trying create the movement for the player I have a problem where the player starts moving randomly up or down on the y-scale. When inspecting my Player.prototype.update method in chrome I can see that this.body.velocity.y is NaN. I have no Idea how it got to be NaN pheraps some issue with the gravity? I have tried various fixes but I can't find the bug in my code. I have looked at numerous tutorials and they all look similar to what Im doing. Please help. Below is my code. player.js // Private var leftKey; var rightKey; var jumpKey; var speed = 150; var jumpSpeed = 250; // Constructor function Player (game, x, y) { Phaser.Sprite.call(this, game, x, y, Player.key); this.anchor.set(0.5,0.5); game.physics.arcade.enableBody(this); this.body.bounce = 0; this.body.collideWorldBounds = true; this.body.allowGravity = true; leftKey = game.input.keyboard.addKey(Phaser.Keyboard.A); rightKey = game.input.keyboard.addKey(Phaser.Keyboard.D); jumpKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); game.add.existing(this); } Player.prototype = Object.create(Phaser.Sprite.prototype); Player.prototype.constructor = Player; // Static Player.preload = function(game) { game.load.image(Player.key, "images/block.png"); }; Player.key = "Player"; Player.prototype.update = function() { this.body.velocity.x = 0; if (leftKey.isDown) { this.body.velocity.x = -speed; } else if (rightKey.isDown) { this.body.velocity.x = speed; } if (jumpKey.isDown && (this.body.onFloor() || this.body.touching.down)) { this.body.velocity.y = -jumpSpeed; } }; module.exports = Player; var Player = require('../models/player.js'); var destiny = {}; /* The main game */ destiny.create = function () { console.info("Find out your destiny!"); // World this.game.stage.backgroundColor = "#5599CC"; this.game.world.setBounds(0, 0, 1000, 500); this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.time.desiredFPS = 30; this.game.physics.arcade.gravity.y = 200; this.allSprites = {}; // Player this.allSprites.destinyPlayer = new Player(this.game,2000,900); // Camera this.game.camera.follow(this.allSprites.destinyPlayer,Phaser.Camera.FOLLOW_PLATFORMER); }; destiny.update = function() { }; destiny.render = function() { this.game.debug.spriteInfo(this.allSprites.destinyPlayer,32,32); this.game.debug.cameraInfo(this.game.camera,32,128); }; module.exports = destiny; My game is loaded in a series of game states (boot, preload, startscreen, preload, game). I have previously not had any problems with that part but if you want to see that code please ask. Here is the error in chrome. Any help is appreciated.
  4. I've been trying to extend the functionality of TweenManager, so it can resume and pause everything within a group. I adapted the code from here: http://jsfiddle.net/lewster32/L3u3gp5k/ http://docs.phaser.io/TweenManager.js.html#sunlight-1-line-127 When debugging with console, _tweens and _add are undefined for each object, so the function doesn't work. I think the code is correct? Any ideas why this isn't working? I'm guessing i've missed something crucial about _tweens. Here's the code: (This goes out to Rich and Lewster) Phaser.TweenManager.prototype.pauseAllFrom = function(obj, children) {console.log('pauseAllFrom', obj.type, obj.name, obj._tweens, obj._add); var o, c, t, len; if (Array.isArray(obj) ) { for (o = 0, len = obj.length; o < len; o++) { this.pauseFrom(obj[o]); } } else if ( (obj.type === Phaser.GROUP || obj.type==7) && children){ for (c = 0, len = obj.children.length; c < len; c++){ this.pauseFrom(obj.children[c]); } } else { for (t = 0, len = this._tweens.length; t < len; t++){ if (obj === this._tweens[t]._object){ console.log('pauseFrom _tweens:',this._tweens[t]); this._tweens[t].pause(); } } for (t = 0, len = this._add.length; t < len; t++){ if (obj === this._add[t]._object){ console.log('pauseFrom _add:',this._add[t]); this._add[t].pause(); } } }};Phaser.TweenManager.prototype.resumeAllFrom = function(obj, children) {console.log('resumeAllFrom', obj.type, obj.name, obj._tweens, obj._add); var o, c, t, len; if (Array.isArray(obj) ) { for (o = 0, len = obj.length; o < len; o++) { this.pauseFrom(obj[o]); } } else if ( (obj.type === Phaser.GROUP || obj.type==7) && children){ for (c = 0, len = obj.children.length; c < len; c++){ this.pauseFrom(obj.children[c]); } } else { for (t = 0, len = this._tweens.length; t < len; t++){ if (obj === this._tweens[t]._object){ this._tweens[t].resume(); } } for (t = 0, len = this._add.length; t < len; t++){ if (obj === this._add[t]._object){ this._add[t].resume(); } } }};I also had to add a condition for the object type, as the console wasn't recognising Phaser.GROUP, and spitting out a number for each object type. // from thiselse if (obj.type === Phaser.GROUP && children){// to thiselse if ( (obj.type === Phaser.GROUP || obj.type==7) && children){Any help would be greatly appreciated. Thanks
  5. How would I add animations to a class I've extended from sprite? I'm trying to follow the information Extending Sprite Demos 1 and 2 but neither animate the sprites and if I add 'this.animations.add' in the update function I get the error 'animations is not defined'. The code to my class is here: Puppy = function(thisGame,x,y) { Phaser.Sprite.call(this,thisGame,x,y,'puppy');};Puppy.prototype = Object.create(Phaser.Sprite.prototype);Puppy.prototype.constructor = Puppy; Puppy.prototype.create = function() { this.animations.add('idleleft',[0,1,2],4,true); this.animations.add('idleright',[3,4,5],4,true); this.animations.play('idleright');};puppy = new Puppy(this,100,256);this.add.existing(puppy);Other than animations it seems to work. Any help would be greatly appreciated.