Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitwise operators instead of deprecated bit library #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "bit"


local function load(filename)
local tilemap = Sprite.new()
Expand Down Expand Up @@ -51,15 +51,15 @@ local FLIPPED_DIAGONALLY_FLAG = 0x20000000;
local flipDia
if gid ~= 0 then
-- Read flipping flags
flipHor = bit.band(gid, FLIPPED_HORIZONTALLY_FLAG)
flipVer = bit.band(gid, FLIPPED_VERTICALLY_FLAG)
flipDia = bit.band(gid, FLIPPED_DIAGONALLY_FLAG)
flipHor = gid & FLIPPED_HORIZONTALLY_FLAG
flipVer = gid & FLIPPED_VERTICALLY_FLAG
flipDia = gid & FLIPPED_DIAGONALLY_FLAG
-- Convert flags to gideros style
if(flipHor ~= 0) then flipHor = 4 end --TileMap.FLIP_HORIZONTAL end
if(flipVer ~= 0) then flipVer = 2 end --TileMap.FLIP_VERTICAL end
if(flipDia ~= 0) then flipDia = 1 end --TileMap.FLIP_DIAGONAL end
-- Clear the flags from gid so other information is healthy
gid = bit.band(gid, bit.bnot(bit.bor(FLIPPED_HORIZONTALLY_FLAG, FLIPPED_VERTICALLY_FLAG, FLIPPED_DIAGONALLY_FLAG)))
gid = gid & ~ (FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG)
end

local tileset = gid2tileset(map, gid)
Expand Down Expand Up @@ -88,7 +88,7 @@ local FLIPPED_DIAGONALLY_FLAG = 0x20000000;
local ty = math.floor((gid - tileset.firstgid) / tileset.sizex) + 1

-- Set the tile with flip info
tilemap:setTile(x, y, tx, ty, bit.bor(flipHor, flipVer, flipDia))
tilemap:setTile(x, y, tx, ty, flipHor| flipVer| flipDia)
-- Reset vars, so they dont confuse us in the next iteration
flipHor, flipVer, flipDia = 0, 0, 0

Expand Down