Nomid

Members
  • Content Count

    5
  • Joined

  • Last visited

About Nomid

  • Rank
    Newbie
  • Birthday 03/22/1997

Profile Information

  • Gender
    Male
  • Location
    Napoli, Italy
  • Interests
    Programming VC++ VC# PHP JavaScript TypeScript Ruby, Digital & Traditional drawing (mainly animals), Music Composing (OST, classical, rock, EDM)

Contact Methods

  • Skype
    ray.97
  1. Yes, I read about that after finding the solution. Anyway, I took a look at the resulting JS, finding it interesting how it is structured. This is because, technically JS is not OOP, since prototypes only emulate the way we're used to instance objects. It was very clear, thank you
  2. Understood, so the scope in my code is switched to the window object. Thank you! window.addEventListener("keypress", this.updateKeys.bind(this)); window.addEventListener("keyup", this.updateKeys.bind(this)); Worked chg and Matt were very close to the solution of the "undefined" issue. https://github.com/Microsoft/TypeScript/wiki/'this'-in-TypeScript After reading this extract So, to make it work, I did: public update = (time: number) => { this.context.fillStyle = "red"; this.context.fillRect(0, 0, this.context.canvas.width, this.context.canvas.height); this.Ball.update(time); this.Paddle.update(time, this.pressed_keys); }; Thanks to all for your help!!
  3. This is what I read from here: http://www.typescriptlang.org/Handbook#classes, maybe did I misunderstand it? Anyway Matt's solution is ok, I was just wondering why the constructor didn't create the member itself, sorry for that. So it doesn't work just as javascript does. In JavaScript you declare objects like this: var obj = {}; I thought that an accessor like obj[prop] could be fine in TypeScript too.
  4. I read that when specifying constructor(public member : any), member becomes a public property of the object and is auto-assigned (from typescriptlang official). For the bindings, the argument is passed as the listener works, the problem is that pressed_keys is seen as undefined in that context
  5. Hello, this is my first topic on this board. I'm coding a simple BreakOut clone in TypeScript. My app consists of a main BreakOut class and the instances for Ball, Paddle and the canvas context. BreakOut.ts /** * Created by Nomid on 20/01/2016. */ /// <reference path="GameObject.ts"/> /// <reference path="Ball.ts"/> /// <reference path="Paddle.ts"/> /// <reference path="Direction.ts"/> /// <reference path="Sprite.ts"/> /// <reference path="Key.ts"/> class BreakOut { Ball : Ball; Paddle : Paddle; private pressed_keys : { [keycode: number] : boolean }; update(time: number): void { this.context.fillStyle = "red"; this.context.fillRect(0, 0, this.context.canvas.width, this.context.canvas.height); this.Ball.update(time); this.Paddle.update(time, this.pressed_keys); } updateKeys(E: KeyboardEvent) { this.pressed_keys[E.which || E.keyCode] = !this.pressed_keys[E.which || E.keyCode]; } constructor(public context: CanvasRenderingContext2D) { this.Ball = new Ball(context); this.Paddle = new Paddle(context); this.pressed_keys = []; window.addEventListener("keypress", this.updateKeys); window.addEventListener("keyup", this.updateKeys); } } It compiles without errors, but when I run it, these errors appear: BreakOut is initialized as follows: // jQuery 2.2.0 $(document).ready(function() { var Canvas = $("<canvas/>") .attr("width", window.innerWidth) .attr("height", window.innerHeight) .appendTo("body"); window.Game = new BreakOut(Canvas[0].getContext("2d")); window.requestAnimationFrame(Game.update); }); Thank you for helping me.