Display

Type [gd]   

(abstract) class

Inheritance

Display ➝ Object

Overview

This is a base class of all display-related classes such as Image,

Group, Sprite, Text, Line, etc. Note that this is an abstract class

and cannot be instantiated.

See also

Image, Group, Sprite, ImageRegion, Line, Shape



  This is a base class of all display-related classes such as Image, Group, Sprite,

Text, Line, etc. All the drawing objects has the following basic properties:




name

value


x

x-coordinate (number)


y

y-coordinate (number)


rot

rotational angle (number in degree)


alpha

transparency (0~1)


scale

scale factor


scaleX

scaleY

x-axis scale factor

y-axis scale factor



Additional properties are x- and y- value of anchor point as follows.




name

value


anchorX

anchorY

x-location of the origin point (0~1)

y-location of the origin point (0~1)



The display object that has no initial parent (group) is located at the center of the content screen.

All the display objects have initial anchor points at the center of them.



These properties can be set by the following public method.

Note that all the set-related methods return 'self '.


method

description

return value

obj:setXY(x,y)

set x and y values

self

obj:setX(n)

set x value as n

self

obj:setY(n)

set y value as n

self

obj:setRot(n)

set rotational angle as n (degree)

self

obj:setScale(n)


obj:setScaleX(n)

obj:setScaleY(m)

obj:setScaleXY(n,m)

set both xscale and yscale as n


set xscale as n

set yscale as m

set xscale as n and yscale as m (n≠m)

self


self

self

self

obj:setAlpha(n)

set alpha as n (n is a real value between 0 to 1)

self

obj:set(table)

set multiple properties at once

self

obj:setAnchor(n,m)

set xanchor, yanchor as n, m

self

obj:hide() or 

obj:setVisible(false)

hide object


self

obj:show() or

obj:setVisible(true)

show object

self

obj:tint(r,g,b)

sets the red, green, and blue channel multipliers

(r, g, b are real number between 0 and 1)

self



The basic properties can be obtained by the following public methods:


method

description

return value

obj:getXY()

get x and y coordinates

number,number

obj:getX()

get x coordinate

number

obj:getY()

get y coordinate

number

obj:getRot()

get rotational angle (in degree)

number

obj:getScale()


obj:getScaleX()

obj:getScaleY()

obj:getScaleXY()

returns (xscale+yscale)/2


get xscale

get yscale

get xscale and yscale

number


number

number

number,number

obj:getAlpha()

get alpha

number

obj:getAnchor()

obj:getAnchorX()

obj:getAnchorY()

get x-anchor and y-anchor

num, num

obj:isVisible()

If object is now showing, return true

bool

obj:getGlobalXY()

get global (screen) x-y coordinates of

the origin of obj


num, num

obj:getGlobalXY(x,y)

get global (screen) x-y coordinates of

the given local x-y coordinates of obj


obj:getParent()

get parent (group) object

group object

obj:getWidth()

obj:getHeight()


get width of object

get height of object

(Note: Group objects returns 0 )

number

number



There are methods that cause movements of a display object.


method

description

return value

obj:setDx(n)

increase x by n  every frame

self

obj:setDy(n)

increase y by x   every frame

self

obj:setDrot(n)

increase rotational angle (degree) by n every frame

self

obj:setDscale(n)

obj:setDscaleX(n)

obj:setDscaleY(m)

increase scale by n every frame

increase xscale by n every frame

increase xscale by m every frame

self

self

self

obj:setDalpha(n)

increase alpha by n every frame

self

obj:setDxDy(n,m)

increase x by n and y by m every frame

self

obj:stopMove()

cancel all (d-related) movements

self

obj:pauseMove()

pause all (d-related) movements

self

obj:resumeMove()

resume all (d-related) movements

self


method

description

return value

obj:getDx()

get dx value

number

obj:getDy()

get dy value

number

obj:getDrot()

get drot value

number

obj:getDscale()

get dscale value

number

obj:getDalpha()

get dalpha value

number

obj:getDxDy()

get dx, dy value

number

obj:getDscaleX()

get dxscale value

number

obj:getDscaleY()

get dyscale value

number



To shift onto specific destination points in a given time, shift() method can be used.


method

description

return value

obj:shift(table)

shift to the specific point in a given time

self

obj:stopShift()

stop current shift

self

obj:pauseShift()

pause current shift


obj:resumeShift()

resume current shift




The methods related to destruction are as follows.


method

description

return value

obj:remove()

remove obj immediately

nil

obj:removeAfter(ms)

remove obj after ms milli-seconds

self

obj:removeIfOut()

remove if obj is out of the screen

self

obj:isRemoved()

return true if the obj is already removed

bool

<Note> if user-definded obj:update() method returns 'true', then the obj is immediately

removed.



There is a method that occurs timer event in the object


method

description

return value

obj:addTimer(t,fn[,loops[,onEnd]])

generate timer event

Timer object



There are methods that control touch or tap events.


method

description

return value

obj:onTap(e)

user-defined function that handles tap


obj:onTouch(e)

user-defined function that handles touch event


obj:stopTouch()

disables touch input

self

obj:resumeTouch()

enables touch input

self

obj:stopTap()

disables tap input

self

obj:resumeTap()

enables tap input

self



The user can define update() method. If it is defined, it is called every frame..


method

description

return value

obj:update()

user-defined function that is called in every frame (Note : if obj:update() returns true, then the obj is removed immediately.)

user-defined value

obj:stopUpdate()

pause all the updates including d-related movements and shift (and internal updates)

self

obj:resumeUpdate()

enable update

self



There is a method that inserts the display object into a Group object:


method

description

return value

obj:addTo(group)

add obj into the group object

self



The individual display object can be tagged with a name or (id) number :


method

description

return value

obj:tag(label)

obj is tagged with given label(string)

self

obj:detag()

remove tag that had been given

self

Display.collect(label)

(static method) return the table that

contains all display objects tagged with

label

table



  Display methods related to checking collision between Image, Sprite, and Shape

objects (e.g., Rect, Polygon, Circle, etc) are as follows.

  The collision checking area is automatically created according to the shape of

each object.


method

description

return value

obj:isHit(obj2)

return true if obj collides into obj2

boolean

obj:setHitPoint(x,y)

set hit area of obj as the given point (x,y)

self

obj:setHitCircle(r [,x,y])

set hit area of obj as the circle with the given radius r, and center point (x,y)

self

obj:collectHit(label)

collect all the objects that are tagged by label and that collide into obj

nil or

table

obj:noHit()

ban collision checking of obj

self


Note:

  • The math calculation demands between circle-vs-circle or point-vs-circle and point-vs-polygon is much smaller than those between polygon-vs-polygon or polygon-vs-circle.

  • Therefore, it is advantageous to set the collision area of a small polygon as a point (by obj:setHitPoint() method) or a circle (by obj:setHitCircle() method).

댓글 없음:

댓글 쓰기