我想要一个既有物理也有动画序列的游戏对象。我想用一个带有预定义序列的精灵表来动画我的角色,同时利用重力,速度和其他物理效果。Corona SDK动画newImageRect
是否可以将动画序列添加到newImageRect
。或者添加物理到newSprite
?或者将一个精灵加入一个矩形?
我想要一个既有物理也有动画序列的游戏对象。我想用一个带有预定义序列的精灵表来动画我的角色,同时利用重力,速度和其他物理效果。Corona SDK动画newImageRect
是否可以将动画序列添加到newImageRect
。或者添加物理到newSprite
?或者将一个精灵加入一个矩形?
要建立在Corona SDK动画,最好使用此resource
您可以使用此代码
display.setStatusBar(display.HiddenStatusBar)
-- lua data file that Texture packer published
-- it contains the data required by newImageSheet
-- and also contains a function to retrieve frames
-- by their names sheetInfo:getFrameIndex("sprite")
local sheetInfo = require("spritesheet")
-- init the image sheet
local myImageSheet = graphics.newImageSheet("spritesheet.png",
sheetInfo:getSheet())
local sequenceData = {
-- set up anmiation
{
name="walk", -- name of the animation (used with setSequence)
sheet=myImageSheet, -- the image sheet
start=sheetInfo:getFrameIndex("capguy/walk/0001"), -- name of the first frame
count=8, -- number of frames
time=1000, -- speed
loopCount=0 -- repeat
},
}
capguy = display.newSprite(myImageSheet, sequenceData)
-- set initial position and direction
capguy.x = 160
capguy.y = 300
direction = 1
-- start walking animation
capguy:setSequence("walk")
capguy:play()
对于物理连接动画 - Physics Editor
我想通了,在精灵表没有像我想要的那样行事,因为它没有被添加到世界中。这条线解决了这个问题。 world:insert(capguy)