RonanTheAccel

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. AS3 / Flash was the previous preferred language for web games , so there are a lot of people who programs with AS3, i would suggest a guide to migrate from AS3 to Phaser (for newbies like me!)
  2. Hi guys, i'm having trouble with this code , the error is "Cannot read property 'velocity' of null" in player.body.velocity.y = Math.abs(playerSpeed); <!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Drop Wizard</title> <script type="text/javascript" src="phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style></head><body><script type="text/javascript">var game = new Phaser.Game(480, 320, Phaser.CANVAS, '', { preload: preload, create: create, update: update });var playerSpeed = 150;var player;var platformGroup;function preload() { game.load.image("platform180","platform180.png"); game.load.image("platform120","platform120.png"); game.load.image("player","player.png"); game.load.image("ground","ground.png");}function create() { platformGroup = game.add.group(); game.physics.startSystem(Phaser.Physics.ARCADE); player = game.add.sprite(240,0,"player"); player.anchor.setTo(0.5); game.physics.enable(player,Phaser.Physics.Arcade); game.physics.arcade.gravity.y = playerSpeed; addPlatform(240,60,"platform180"); addPlatform(340,140,"platform120"); addPlatform(140,140,"platform120"); addPlatform(420,220,"platform120"); addPlatform(60,220,"platform120"); addPlatform(100,316,"ground"); addPlatform(380,316,"ground"); game.input.onDown.add(changeDir,this);}function addPlatform(posX,posY,asset){ platform = game.add.sprite(posX,posY,asset); platform.anchor.setTo(0.5); game.physics.enable(platform,Phaser.Physics.ARCADE); platform.body.allowGravity = false; platform.body.immovable = true; platformGroup.add(platform);}function update() { player.body.velocity.y = Math.abs(playerSpeed); player.body.velocity.x = 0; player.body game.physics.arcade.collide(player, platformgroup, movePlayer); if(player.y>320){ player.y = 0 } if(player.x<12){ player.x=12; playerSpeed*=-1 } if(player.x>468){ player.x=468; playerSpeed*=-1 }trace(player); trace(player.body) trace(player.body.velocity)}function movePlayer(){ player.body.velocity.x = playerSpeed} function changeDir(){ playerSpeed *= -1; }</script></body></html>
  3. Hello Phaser friends!, So i'm studying game dev and we only program in AS3 with Flash Develop, so i'm used to an IDE that auto completes everything and helps a lot. Now i downloaded Phaser, Sublime Text 2 and i'm ready to code. I need to know the main differences, for example. how do you extend a class, i'm used to make something like (sorry, it's long) So, i would really appreciate if you can stand out the main points!, i know it's an entire language and framework so i will try to follow more tutorials, but if you can explain the main differences i would really love it. Thanks! package game { import api.CAnim; import api.CBulletManager; import api.CEnemyManager; import api.CGame; import api.CGameObject; import api.CGenericEnemy; import api.CHelper; import api.CKeyPoll; import api.CMath; import api.CMouse; import flash.automation.MouseAutomationAction; import flash.display.MovieClip; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import game.states.CLevelState; import game.states.CLoseState; public class CPlayer extends CGameObject { private var mMC:MovieClip; private var mState:int; private const STATE_STAND:int = 0; private const STATE_FREEZE:int = 2; private const STATE_JUMP_DYING:int = 3; // Lleva el tiempo del estado. En frames. private var mTimeState:int; private var mYFloor:int; private var mAnim:CAnim; private const WALK_SPEED:int = 10; private var mAngle:int = 0; private const ANG_SPEED:int = 5; private const SPEED_BULLET:int = 15; private const MAX_SPEED_SHIP:int = 5; private const INC_SPEED_SHIP:Number = 0.1; private var mSpeed:Number = 0.0; private const FRICTION:Number = 0.95; private const ACCELERATION:Number = 0.03; private var mAccel:Number = 0.0; private const MAX_ACCELERATION:Number = 0.5; public function CPlayer(aRadius:int) { setRadius(aRadius); mMC = new CAssets.SHIP as MovieClip; CGame.inst().getStage().addChild(mMC); mYFloor = 600 - aRadius; mAnim = new CAnim(); setX(400); setY(600 - 40); setFriction(FRICTION); setState(STATE_STAND); } override public function update():void { var enemy:CGenericEnemy; super.update(); mTimeState++; mAnim.update(); if (mState == STATE_STAND) { if (CKeyPoll.firstPress(CKeyPoll.SPACE) || CMouse.firstPress()) { fire(); } // MOUSE //lookAt(CMouse.getMouseX(), CMouse.getMouseY()); // TECLADO if (CKeyPoll.pressed(CKeyPoll.LEFT)) { setAngle(mAngle - ANG_SPEED); } else if (CKeyPoll.pressed(CKeyPoll.RIGHT)) { setAngle(mAngle + ANG_SPEED); } if (CKeyPoll.pressed(CKeyPoll.UP)) { mAccel += ACCELERATION; if (mAccel > MAX_ACCELERATION) { mAccel = MAX_ACCELERATION; } } else { mAccel = 0; } setAccelX(mAccel * Math.cos(CMath.degToRad(mAngle))); setAccelY(mAccel * Math.sin(CMath.degToRad(mAngle))); if (getY() < getRadius()) { setY(getRadius()); setVelY(0); } // Control de borde abajo. if (getY() > mYFloor) { setY(mYFloor); setVelY(0); } enemy = CEnemyManager.inst().collides(this) as CGenericEnemy; if (enemy != null) { hitByEnemy(); // TODO: Matar el enemigo. } } else if (mState == STATE_FREEZE) { if (mTimeState > 30) { setState(STATE_JUMP_DYING); } } else if (mState == STATE_JUMP_DYING) { setAngle(mAngle + 20); if (mTimeState > 60) { setState(STATE_STAND); //setDead(true); } } } override public function render():void { super.render(); mMC.gotoAndStop(mAnim.getCurrentFrame()); mMC.rotation = mAngle; mMC.x = getX(); mMC.y = getY(); } // Funcion invocada cuando un enemigo nos toca. public function hitByEnemy():void { if (mState == STATE_STAND /*|| mState == STATE_WALKING*/) { setState(STATE_FREEZE); } } private function setState(aState:int):void { mState = aState; mTimeState = 0; if (mState == STATE_STAND) { mAnim.init(1, 1, 0); setAngle(0); setX(400); setY(300); setVelX(0); setVelY(0); setAccelX(0); setAccelY(0); } else if (mState == STATE_FREEZE) { mAnim.init(14, 14, 0); setAngle(0); setVelX(0); setVelY(0); setAccelX(0); setAccelY(0); } else if (mState == STATE_JUMP_DYING) { mAnim.init(14, 14, 0); setAngle(0); setVelX(0); setVelY(-10); setAccelX(0); setAccelY(1); } } public function fire():void { var b:CPlayerBullet = new CPlayerBullet(0x000000, 10); b.setX( getX() + getRadius() * Math.cos(CMath.degToRad(mAngle))); b.setY( getY() + getRadius() * Math.sin(CMath.degToRad(mAngle))); b.setVelX( SPEED_BULLET * Math.cos(CMath.degToRad(mAngle))); b.setVelY( SPEED_BULLET * Math.sin(CMath.degToRad(mAngle))); b.setAccelX(0); b.setAccelY(0); b.render(); CBulletManager.inst().add(; } override public function destroy():void { super.destroy(); CHelper.removeDisplayObject(mMC); mMC = null; mAnim.destroy(); mAnim = null; } private function setAngle(aAngle:Number):void { mAngle = CMath.clampDeg(aAngle); } private function getAngle():Number { return mAngle; } private function lookAt(aX:Number, aY:Number):void { var y:Number = CMouse.getMouseY() - getY(); // cat. op. var x:Number = CMouse.getMouseX() - getX(); // cat. ady. setAngle(CMath.radToDeg(Math.atan2(y, x))); } }}