1 decade ago by TObe
Hi, I'm trying to run my game in iOS but when I try to run the game in the simulator says that can't load one of the entities. Here's is the main.js and the entity that I'm trying to load:
Entity:
ig.module( 'game.main' ) .requires( 'impact.game', 'impact.font', 'plugins.director.director', 'game.entities.player', 'game.entities.spike', 'game.entities.distComidaAnimal', 'game.entities.changuito', 'game.entities.reja', 'game.entities.visitante', 'game.levels.titulo', 'game.levels.test', 'plugins.ios.ios' ) .defines(function(){ MyGame = ig.Game.extend({ gravity: 0, // All entities are affected by this // Load a font font: new ig.Font( 'media/04b03.font.png' ), // timer de distractor timerDistractor: new ig.Timer(), timerFijadorDistractor: new ig.Timer(), // timer de visitantes timerVisitante: new ig.Timer(), init: function() { //if( ios ) { // When the 'ios' object is defined, we're running // inside iOSImpact // Define an area of the screen as button. The syntax is: // x, y, width, height, action ig.input.bindTouchArea( 0, 224, 80, 96, 'left' ); ig.input.bindTouchArea( 80, 224, 80, 96, 'right' ); ig.input.bindTouchArea( 160, 224, 160, 96, 'up' ); ig.input.bindTouchArea( 240, 224, 240, 96, 'down' );*/ }else{ // Bind keys ig.input.bindTouch( '#buttonLeft', 'left' ); ig.input.bindTouch( '#buttonRight', 'right' ); ig.input.bindTouch( '#buttonUp', 'up' ); ig.input.bindTouch( '#buttonDown', 'down' ); } // Load the LevelTest as required above ('game.level.test') this.loadLevel( LevelTest ); this.myDirector = new ig.Director(this, [LevelTitulo, LevelTest]); this.rejaRota = 0; this.timerDistractor.set( 10 ); this.timerFijadorDistractor.set( 5 ); this.timerVisitante.set((Math.random()*10)*2); // variables globales y banderas nuevoDistractor = false; this.titulo = 0; dinero = 0; felicidad = 50; }, update: function() { // screen follows the player var player = this.getEntitiesByType( 'EntityPlayer' )[0]; var distractores = ig.game.getEntitiesByType( 'EntitySpike' ); if(this.titulo == 0){ if( ig.input.pressed('left') ){ this.myDirector.nextLevel(); this.titulo = 1; } } if(distractores.length){ // colocar el distractor distractores[distractores.length - 1].activo = true; } // pinta distractores if(this.timerDistractor.delta() >= 0 && this.titulo == 1){ ig.game.spawnEntity( EntitySpike, 125, 130, {flip:this.flip} ); this.timerDistractor.reset(); nuevoDistractor = true; } // fija distractor if(this.timerFijadorDistractor.delta() >= 0){ nuevoDistractor = false; this.timerFijadorDistractor.reset(); } // pinta visitantes if(this.timerVisitante.delta() >= 0 && this.titulo == 1){ ig.game.spawnEntity( EntityVisitante, 145, 74, {flip:this.flip} ); this.timerVisitante.reset(); dinero += 5; } // Update all entities and BackgroundMaps this.parent(); }, draw: function() { // Draw all entities and BackgroundMaps this.parent(); this.font.draw( 'Zoo Keeper Beta', 50, 10 ); if(this.titulo == 0){ this.font.draw( 'Presiona TESTIzquierda', 50, 18 ); this.font.draw( 'para comenzar', 50, 26 ); } } }); // Start the Game with 60fps, a resolution of 240x160, scaled // up by a factor of 2 if( ig.ua.mobile ) { // Disable sound for all mobile devices ig.Sound.enabled = false; } if( ig.ua.iPhone4 ) { // The iPhone 4 has more pixels - we'll scale the // game up by a factor of 4 ig.main('#canvas', MyGame, 60, 160, 160, 4); } else if( ig.ua.mobile ) { // All other mobile devices ig.main('#canvas', MyGame, 60, 160, 160, 2); } else { // Desktop browsers ig.main('#canvas', MyGame, 60, 160, 160, 4); } });
Entity:
ig.module( 'game.entities.changuito' ) .requires( 'impact.entity' ) .defines(function(){ EntityChanguito = ig.Entity.extend({ size: {x: 9, y: 14}, maxVel: {x: 75, y: 75}, friction: {x: 150, y: 0}, type: ig.Entity.TYPE.B, // Evil enemy group checkAgainst: ig.Entity.TYPE.A, // Check against friendly collides: ig.Entity.COLLIDES.PASSIVE, health: 2700, loco: 0, speed: 14, flip: true, conteoInicial: 0, animSheet: new ig.AnimationSheet( 'media/changuito.png', 9, 14 ), timer: new ig.Timer(), timerStandBy: new ig.Timer(), init: function( x, y, settings ) { this.parent( x, y, settings ); this.addAnim( 'standby', 0.1, [0,1] ); this.addAnim( 'run', 0.1, [0,1,2,3] ); this.anims.run.flip.x = true; this.anims.run.flip.y = true; this.timerStandBy.set( 15 ); this.timer.set( 5 ); this.moviendose = 0; }, update: function() { var aleatorioX = Math.random() < 0.5 ? -1 : 1; var aleatorioY = Math.random() < 0.5 ? -1 : 1; if(this.moviendose == 0){ var velAleatoriaX = Math.floor(Math.random()*41) var velAleatoriaY = Math.floor(Math.random()*41) } var tiempoRandom = Math.floor(Math.random()*11) if(this.conteoInicial == 0){ //Obtiene la cantidad inicial de rejas. Osea reja completa this.cantRejas = ig.game.getEntitiesByType( 'EntityReja' ).length; this.conteoInicial = 1; } var cantidad = ig.game.getEntitiesByType( 'EntityDistComidaAnimal' ).length; // en caso que haya distractores if(cantidad > 0 && this.loco == 0){ var distractor = ig.game.getEntitiesByType( 'EntityDistComidaAnimal' )[cantidad-1]; var distancia = this.distanceTo(distractor); var indice = 0; var indiceFinal = cantidad-1; for(indice=0;indice<cantidad;indice++){ distractor = ig.game.getEntitiesByType( 'EntityDistComidaAnimal' )[indice]; if(distancia > this.distanceTo(distractor)){ distancia = this.distanceTo(distractor); indiceFinal = indice; } } var distractorFinal = ig.game.getEntitiesByType( 'EntityDistComidaAnimal' )[indiceFinal]; var angulo = this.angleTo(distractorFinal); } if( this.cantRejas > ig.game.getEntitiesByType( 'EntityReja' ).length){ //Aquí se debe de mover como loco el changuito this.vel.x = this.maxVel['x'] * aleatorioX; this.vel.y = this.maxVel['y'] * aleatorioY; this.loco = 1; }else{ //Aquí debe de ir el movimiento de un changuito enjaulado if(distancia > 0){ this.vel.x = velAleatoriaX * Math.cos(angulo); this.vel.y = velAlearoriaY * Math.sin(angulo); }else if(this.timer.delta()){ moviendose = 1; this.vel.x = velAleatoriaX * aleatorioX; this.vel.y = velAleatoriaY * aleatorioY; //var xdir = 0; //var ydir = this.flip ? -1 : 1; //this.vel.x = this.speed * xdir; //this.vel.y = this.speed * ydir; this.timerStandBy.reset(); }else{ this.vel.x = 0; this.vel.y = 0; if(this.timerStandBy.delta() > 0){ this.timer.set(tiempoRandom); this.moviendose = 0; } } } this.parent(); }, handleMovementTrace: function( res ) { this.parent( res ); // collision with a wall? return! if( res.collision.x ) { this.flip = !this.flip; this.anims.run.flip.x = !this.anims.run.flip.x; }if( res.collision.y ) { this.flip = !this.flip; this.anims.run.flip.y = !this.anims.run.flip.y; } }, check: function( other ) { other.receiveDamage( 10, this ); } }); });