著名跨平台手游引擎Corona SDK的Display对象创建方式汇总:
第一部分:分组类
Group:
display.newGroup()
Container:
display.newContainer( [parent, ] width, height )
第二部分:图像类ImageSheet:(图像列表)
graphics.newImageSheet( filename, [baseDir, ] options )
a 简单模式:
local option ={ width = 50, height = 50, numFrames = 2, border = 0, sheetContentWidth = 100, sheetContentHeight = 50}
b 复杂模式:
local option = {
frames = { {x = 100, y = 100, width = 100, height = 100,}, { ...}, {...}),
border = 0, sheetContentWidth = 100, sheetContentHeight = 50
}
ImageRect:(zoomStrech)display.newImageRect( [parentGroup,] filename, [baseDir,] width, height )
display.newImageRect( [parentGroup,] imageSheet, frameIndex, width, height )
Sprite:display.newSprite( imageSheet, sequenceData )
display.newSprite( parent, imageSheet, sequenceData )
imageSheet可以用graphics.newImageSheet来创建。
sequenceData:
单序列(连续帧)
-- Example assumes 'imageSheet' is already created from graphics.newImageSheet() -- consecutive frames local sequenceData = { name="walking", start=3, count=6, time=100, loopCount = 0, -- Optional ; default is 0 (loop indefinitely) loopDirection = "bounce" -- Optional ; values include "forward" or "bounce" } local character = display.newSprite( imageSheet, sequenceData )
单序列(不连续帧)
-- Example assumes 'imageSheet' is already created using graphics.newImageSheet() -- non-consecutive frames local sequenceData = { name="walking", frames= { 3, 4, 5, 6, 7, 8 }, -- frame indexes of animation, in image sheet time = 240, loopCount = 0 -- Optional ; default is 0 } local character = display.newSprite( imageSheet, sequenceData )
多序列
-- Example assumes 'imageSheet' already created using graphics.newImageSheet() local sequenceData = { { name="walking", start=1, count=3 }, { name="running", frames={ 3, 4, 5, 6, 7, 8 }, time=120, loopCount=4 }, { name="jumping", start=9, count=13, time=300 } } local character = display.newSprite( imageSheet, sequenceData )
多ImageSheet
-- 1st image sheet local sheetData1 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 } local sheet1 = graphics.newImageSheet( "mySheet1.png", sheetData1 ) -- 2nd image sheet local sheetData2 = { width=64, height=64, numFrames=6, sheetContentWidth=384, sheetContentHeight=64 } local sheet2 = graphics.newImageSheet( "mySheet2.png", sheetData2 ) -- In your sequences, add the parameter 'sheet=', referencing which image sheet the sequence should use local sequenceData = { { name="seq1", sheet=sheet1, start=1, count=6, time=220, loopCount=0 }, { name="seq2", sheet=sheet2, start=1, count=6, time=220, loopCount=0 } } local myAnimation = display.newSprite( sheet1, sequenceData ) myAnimation.x = display.contentWidth/2 ; myAnimation.y = display.contentHeight/2 myAnimation:play() -- After a short time, swap the sequence to 'seq2' which uses the second image sheet local function swapSheet() myAnimation:setSequence( "seq2" ) myAnimation:play() end timer.performWithDelay( 2000, swapSheet )
第三部分:形状类
Text:display.newText( options ) -- option field: parent, text, x, y, width, height, font, fontsize, align
display.newText( [parentGroup,] text, x, y, font, fontSize )
display.newText( [parentGroup,] text, x, y, [width, height,] font, fontSize )
display.newRect( x, y, width, height )
Rect:
display.newRect( parent, x, y, width, height )
display.newCircle( xCenter, yCenter, radius )
Circle:
display.newCircle( parent, xCenter, yCenter, radius )
RounderRect:
display.newRoundedRect( x, y, width, height, cornerRadius )
display.newRoundedRect( parent, x, y, width, height, cornerRadius )
Line:
display.newLine( [parentGroup,] x1, y1, x2, y2 [, x3, y3, ... ] )
Polygon:
display.newPolygon( x, y, vertices )
display.newPolygon( parent, x, y, vertices )
local vertices = { 0,-110, 27,-35, 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, }
(企业版中部分暂略)