display:set()

Type      [gd]

method of Display class

Overview

Set multiple properties of Display object.

Return value

self (display object itself)

See also    [bl

Display


Overview 


  The multiple properties of Display class objects that are related to positioning and movement can be set using set() method. The parameter of this method is a single table. This method is useful in the case that more than two properties are to be set at the same time.


Syntax    [bl]


obj:set {


    x=n1,

    y=n2,

    rot = n3,

    scale = n4,

    alpha = n5,

    scaleX=n6,

    scaleY=n7,


    dx=n8,

    dy=n9,

    drot = n10,

    dscale = n11,

    dalpha = n12,

    dscaleX=n13,

    dscaleY=n14,


}


where nk's (k=1,2,...,14) are numbers. Each element can be optionally specified.


  if it is set as dx=1, it means the x-coordinate increases by 1 in every frame. if drot is set to -2, it means the rotational angle decreases by 2 degree in every frame. As a result of drot=-2, the object will rotate counterclockwise. Note that individual position can be set using 


        obj:setX(n1)

        obj:setY(n2)

        obj:setXY(n1,n2)

        obj:setRot(n3)

        obj:setScale(n4)

        obj:setAlpha(n5)

        obj:setScaleX(n6)

        obj:setScaleY(n7)


methods of Display object. Note also that individual movement can be set using 


        obj:setDx(n8)

        obj:setDy(n9)

        obj:setDxDy(n8,n9)

        obj:setDrot(n10)

        obj:setDscale(n11)

        obj:setDalpha(n12)

        obj:setDscaleX(n13)

        obj:setDscaleY(n14)


methods of Display object.



Examples


 In the calling function in Lua language, if it receives only a single table, the parenthesis can be omitted.


local img = Image('moon.png')

img:set{x=100,y=200, rot = 90, scale = 2}


The folloing example sets rot, xscale, and yscale at the same time at which the img object created.


local img = Image('moon.png'):set{rot = 90, scaleX = 2, scaleY = 0.9}


It can be also specified elements for moving.


local img = Image('moon.png'):set{x=100,y=100,dx=1,dy=2}



local img = Image('moon.png'):set{drot=1, dalpah=-0.01}

img:removeafter(1500)


 

local img = Image('moon.png')

img:set{dx=1, dy=2, drot = 2 }


The properties x, y, and rot of img object will be changed by 1,2, and 2 in every frame, which raises a movement of the object.


local img = Image('moon.png'):set{drot = 2, dscaleX = 1/600, dscaleY = -1/1200}


This example sets drot, dxscale, and dyscale at the same time at which the img object created.


  Note that if only one property is to set, it is more efficient to use setdx(), setdy(), setdalpha(), setdscale(),set drot(), setdxscale(), and setdyscale() methods. 


local star = Star(100):setDrot(2)


By this, the 'star' object will rotate clockwise.


댓글 없음:

댓글 쓰기