Forum

> > CS2D > General > Convert Tile in Pos
ForenübersichtCS2D-ÜbersichtGeneral-ÜbersichtEinloggen, um zu antworten

Englisch Convert Tile in Pos

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Re: Convert Tile in Pos

Vectarrio
User Off Offline

Zitieren
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

alt Re: Convert Tile in Pos

DC
Admin Off Offline

Zitieren
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

alt Re: Convert Tile in Pos

Lee
Moderator Off Offline

Zitieren
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

alt hacker4ok

Hacker4ok NEW
User Off Offline

Zitieren
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

alt Re: Convert Tile in Pos

EngiN33R
Moderator Off Offline

Zitieren
@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
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenGeneral-ÜbersichtCS2D-ÜbersichtForenübersicht