1 decade ago by ShawnSwander
/this is a script to look at a tile adjacent to the player in my game. In simple terms right clicking spawns an entity that is the size of the screen that is a blown up version of the tile clicked. Eventually I am going to have the game show any items on the ground there when zoomed in. The problem is some times the wrong tile is shown
I looked for a pattern to why its incorrect but couldn't find one. Any idea why the data on my map might not match what the screen displays?
hexzoom's draw function
I looked for a pattern to why its incorrect but couldn't find one. Any idea why the data on my map might not match what the screen displays?
if( ig.input.pressed('rightclick')){ if (ig.input.mouse.x>110&&ig.input.mouse.x<275&&ig.input.mouse.y>110&&ig.input.mouse.y<275){ tiles = ig.game.getMapByName('hexes'); tilex = parseInt((ig.input.mouse.x-165+this.pos.x)/HEX_SIZE); tiley = parseInt((ig.input.mouse.y-165+this.pos.y)/HEX_SIZE); console.log(tiles.data[tilex][tiley]+"@"+tilex+","+tiley) if (!ig.game.hexzoom){ ig.game.hexzoom = ig.game.spawnEntity(EntityHexzoom, this.pos.x-165,this.pos.y-165,{}); ig.input.unbindAll(); ig.game.screenstate = 1; } ig.game.hexzoom.currentAnim = ig.game.hexzoom.anims[tiles.data[tilex][tiley]-1] }else{ ig.game.player.messagebox = "You cannot see that far."; } }
hexzoom's draw function
draw: function(){ var ctx = ig.system.context; ctx.save(); ctx.translate( ig.system.getDrawPos( this.pos.x.round() - this.offset.x - ig.game.screen.x ), ig.system.getDrawPos( this.pos.y.round() - this.offset.y - ig.game.screen.y ) ); ctx.scale( this.scale.x, this.scale.y ); this.currentAnim.draw( 0, 0 ); ctx.restore(); }