Forum

> > CS2D > General > Convert Tile in Pos
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Convert Tile in Pos

6 replies
To the start Previous 1 Next To the start

old Re: Convert Tile in Pos

Vectarrio
User Off Offline

Quote
Tiles is 32x32, so it will be:
x=tilex*32
y=tiley*32
But I don't know, is it center of tile or top-left corner. So, if it is top-left corner, if you want to set pos to the center, then:
x=tilex*32+16
y=tiley*32+16

old Re: Convert Tile in Pos

DC
Admin Off Offline

Quote
no it's absolutely correct. you are doing something wrong if it doesn't work for you. again:

px and py = position in pixels
tx and ty = position in tiles

position in pixels -> tile position:
px/32 = tx
py/32 = ty

tile position -> position in pixels (top left of tile)
tx*32 = px
ty*32 = py

tile position -> position in pixels (center of tile)
tx*32+16 = px
ty*32+16 = py

old Re: Convert Tile in Pos

Lee
Moderator Off Offline

Quote
An implementation of teleport to tile command:

1
2
3
4
5
6
7
function adm_teletile_admin(p, typ, cmd)
	cmd = args(cmd)
	local i = cmd[1]
	local x = cmd[2]
	local y = cmd[3]
	parse(string.format("setpos %s %s %s", i, x*32+16, y*32+16))
end

http://svn.cs2d.org/amx2d/core/basic.lua

old hacker4ok

Hacker4ok NEW
User Off Offline

Quote
I want to use this too, but my script and your script dont working . I want to when I throw snowball to the ground, snowball will on the ground

Why this isnt work? :
addhook("projectile" , "ball_ground")
function ball_ground(id,x,y)
parse("strip "..id.." 75")
parse("spawnitem "..tx*32.." "..ty*32.." 75")
end

old Re: Convert Tile in Pos

EngiN33R
Moderator Off Offline

Quote
@hacker4ok

Do you know what variables are?

1
2
3
4
5
addhook("projectile" , "ball_ground")
function ball_ground(id,x,y)
parse("strip "..id.." 75")
parse("spawnitem "..math.floor(x/32).." "..math.floor(y/32).." 75")
end
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview