[solved][b42] Non-square tiles seem to cause mouse offset

Where bugs go to lie down and rest

Moderator: Moderator

Post Reply
Message
Author
andar_b
Cornac
Posts: 30
Joined: Thu Nov 08, 2012 6:28 pm

[solved][b42] Non-square tiles seem to cause mouse offset

#1 Post by andar_b »

I'm screwing around with the display settings and I kinda like using rectangular tiles, but after hacking away at my code for hours trying to find why the tooltip was inspecting the tile to the left of where I was actually hovering - I realized it was the rectangular tiles.

Here's a snippet of what I did to my game.lua

Code: Select all

function _M:setupDisplayMode()
	print("[DISPLAY MODE] 32x32 ASCII/background")
 -- when th and tw = 32, mouse works fine. When done like this, mouse is offset.
 -- font_scale = 175, which gives me a reasonably tidy way to adjust font size based on screen resolution. 
 -- It works pretty good everywhere else.
	local th = (self.h/font_scale)*5
	local tw = (self.h/font_scale)*4
	Map:setViewPort(0, 0, self.w, self.h, tw, th, "/data/font/FSEX300.ttf", (self.h/font_scale)*7, true)
	Map:resetTiles()
	Map.tiles.use_images = false
 -- snip
Last edited by andar_b on Sun Nov 18, 2012 5:41 pm, edited 1 time in total.

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: [b42] Non-square tiles seem to cause mouse offset

#2 Post by tiger_eye »

Tiles displayed rectangular should work. I've played around with 'em before.

Do the source images have dimensions that are powers of two?

"th" and "tw" should probably be integers, so perhaps do:

Code: Select all

    local th = math.floor((self.h/font_scale)*5)
    local tw = math.floor((self.h/font_scale)*4)
Is anything else offset, like particles or targeting highlights?
darkgod wrote:OMFG tiger eye you are my hero!

andar_b
Cornac
Posts: 30
Joined: Thu Nov 08, 2012 6:28 pm

Re: [b42] Non-square tiles seem to cause mouse offset

#3 Post by andar_b »

I didn't have targeting highlights or particles, let alone knowing how to activate them. ^.^

Actually, math.floor seems to have corrected the problem. I guess I'm kinda used to C's rounding off of integer values, completely forgot that I should round it manually.

Still leaves me with a few other problems with the tile display, but this issue is solved. It still might make sense to round those values internally if floating point input makes it choke.

Post Reply