Alexandr56

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. I've been trying to rewrite some of my code and came across a problem when i was trying to rewrite the character class. Originally i made it out of a simple circle graphic but recently i decided to make the character out of a sprite. Its a character class that extends PIXI.Sprite.from and used super to send the sprite location. It works on displaying the sprite but when i try to use a function from that class it gives me a "has no function" class hero extends PIXI.Sprite.from { constructor(health, name, spriteSheet, type, x, y) { super(spriteSheet) this.health = health; this.name = name; this.type = type; this.x = x; this.y = y; this.onGround = false; this.speed = { x: 2, y: 2 }; } printing() { console.log("sadasd") } heroMovement(e) { console.log("sd"); `if (e[68].pressed == true) { this.x += this.speed.x; } if (e[65].pressed == true) { this.x -= this.speed.x; } if (e[87].pressed == true) { if () this.y -= (this.speed.y -= .01); } if (e[83].pressed == true && this.onGround == false) { this.y += this.speed.y; }` } } heres the full code from the main script "use strict"; let stage; let gameScene; let achy; const app = new PIXI.Application({ width: window.innerWidth - 20, height: window.innerHeight - 20 }); console.log(window.innerHeight) document.body.appendChild(app.view); // constants let Alex; const sceneWidth = app.view.width; const sceneHeight = app.view.height; let tileSize = 16 const bet = new PIXI.Sprite() app.loader.onComplete.add(setup); app.loader.load(); //PIXI.Loader.shared.add("images/tilesheet.json").load(setup); // add it to the stage // pre-load the images function setup() { let ale = new PIXI.Sprite.from('images/spritef.png') Alex = new hero(1, "Alex", 'images/spritef.png', "archer", 0, 0); let test = new PIXI.BaseTexture('images/tilesheet.png') let tileText = []; for (let i = 0; i < 7 * 11; i++) { let x = i % 7; let y = Math.floor(i / 7); tileText.push(new PIXI.Texture(test, new PIXI.Rectangle(x * tileSize, y * tileSize, tileSize, tileSize))); } let scaler_x = window.innerWidth / (16 * map.width) let scaler_y = window.innerHeight / (16 * map.height) console.log(scaler_x) let worldMap = new PIXI.Container(); for (let y = 0; y < map.height; y++) { for (let x = 0; x < map.width; x++) { let tiles = map.tiles[y * map.width + x]; let sprite = new PIXI.Sprite(tileText[tiles]) sprite.x = x * tileSize * scaler_x; sprite.y = y * tileSize * scaler_y; sprite.scale.x = scaler_x sprite.scale.y = scaler_y worldMap.addChild(sprite) } } let a = new PIXI.Sprite(tileText[0]) stage = app.stage; gameScene = new PIXI.Container(); stage.addChild(worldMap) //gameScene.addChild(tils) //Alex.scale.x = scaler_x; //Alex.scale.y = scaler_y gameScene.addChild(Alex) stage.addChild(gameScene) app.ticker.add(gameLoop) } function gameLoop() { //Angel.printy(); //Alex.heroMovement() keyBoard(); } const controller = { 87: { pressed: false }, 83: { pressed: false }, 68: { pressed: false }, 65: { pressed: false }, } function keyBoard() { /*document.keyup = function(e) { e = e || window.events; Alex.heroMovement(e) };*/ document.addEventListener("keydown", (e) => { if (controller[e.keyCode]) { controller[e.keyCode].pressed = true } }) document.addEventListener("keyup", (e) => { if (controller[e.keyCode]) { controller[e.keyCode].pressed = false } }) Alex.heroMovement(controller) }