Forum

> > CS2D > Scripts > Scaling Image
Forums overviewCS2D overview Scripts overviewLog in to reply

English Scaling Image

5 replies
To the start Previous 1 Next To the start

old Scaling Image

Dousea
User Off Offline

Quote
As title says, I want code that scales an image. Image that I am talking about is a block with 32 x 32 pixels. Actually it's block.bmp in your gfx folder. This image will scale automatically when I press attack button (not attack2). For an example, I pressed the attack button on tile x 16 and y 15. Then I expand it by moving the mouse to tile x 25 and y 18. The size of the image will be 288 pixels at x and 96 pixels at y, or the scale factors will be x 9 and y 3. Top left corner of the image stays at tile x 16 and y 15 and the bottom right corner will be placed at tile x 25 and y 18. If you need more information, comment it.

old Re: Scaling Image

AlcatrazZ
BANNED Off Offline

Quote
More informations?! I don't understand this.
Please write here what you want to.
user Dousea has written
I pressed the attack button on tile x 16 and y 15.

So, you said there about mouse position at screen?
soo..., you want to create a resizable image by mouse?
edited 3×, last 05.06.14 02:16:53 pm

old Re: Scaling Image

Devil-Thanh
GAME BANNED Off Offline

Quote
@user Dousea: maybe this is what you need,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function Array(m,v)
     local array = {}
     for i = 1, m do
          array[i]=v
     end
     return array
end

img = Array(32,0)
X = Array(32,0)
Y = Array(32,0)
key = Array(32,false)


addhook("attack","attack")
function attack(id)
if key[id] then
	key[id] = false
else
	reqcld(id,2)
	key[id] = true
end
end

addhook('clientdata','request')
function request(id,m,x,y)
     if m == 2 then
			if not key[id] then
				img[id] = image("gfx/block.bmp",0,0,0)
				imagepos(img[id],x,y,0)
				X[id] = x
				Y[id] = y
			else
				imagepos(img[id], X[id]+(x-X[id])/2, Y[id]+(y-Y[id])/2,0)
				imagescale(img[id], math.abs(X[id]-x)/32, math.abs(Y[id]-y)/32)
			end
     end
end

addhook("always","always")
function always()
for id = 1,32 do
	if player(id,"exists") then
		if key[id] then
			reqcld(id,2)
		end
	end
end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview