Как оживить мяч в короне sdk
Привет мне нужна помощь с этим кодом я пытаюсь заставить три шара подпрыгивать, оживляя это. Я нашел некоторый код, который может помочь в образце кода Corona SDK. я пытаюсь изменить изображение с круга на изображение, которое я имею в своей папке, но теперь удача, это не будет работать. Кроме того, я использую раскадровку API, мне действительно нужно это спасибо, я новичок в Corona SDK.
это пример кода
этот код работает для меня, но я хочу добавить несколько воздушных шаров, которые будут подпрыгивать в их собственном направлении и подпрыгивать друг к другу и менять направление. Я вроде застрял на этом, может кто-то поможет, спасибо:)....................
вот код, который вы просите извините, что так долго
local function newBall( params )
local xpos = display.contentWidth*0.5
local ypos = display.contentHeight*0.5
local circle = display.newCircle( xpos, ypos, params.radius );
circle:setFillColor( params.r, params.g, params.b, 255 );
circle.xdir = params.xdir
circle.ydir = params.ydir
circle.xspeed = params.xspeed
circle.yspeed = params.yspeed
circle.radius = params.radius
return circle
end
local params = {
{ radius=20, xdir=1, ydir=1, xspeed=2.8, yspeed=6.1, r=255, g=0, b=0 },
{ radius=12, xdir=1, ydir=1, xspeed=3.8, yspeed=4.2, r=255, g=255, b=0 },
{ radius=15, xdir=1, ydir=-1, xspeed=5.8, yspeed=5.5, r=255, g=0, b=255 },
-- newBall{ radius=10, xdir=-1, ydir=1, xspeed=3.8, yspeed=1.2 }
}
local collection = {}
-- Iterate through params array and add new balls into an array
for _,item in ipairs( params ) do
local ball = newBall( item )
collection[ #collection + 1 ] = ball
end
-- Get current edges of visible screen (accounting for the areas cropped by "zoomEven" scaling mode in config.lua)
local screenTop = display.screenOriginY
local screenBottom = display.viewableContentHeight + display.screenOriginY
local screenLeft = display.screenOriginX
local screenRight = display.viewableContentWidth + display.screenOriginX
function collection:enterFrame( event )
for _,ball in ipairs( collection ) do
local dx = ( ball.xspeed * ball.xdir );
local dy = ( ball.yspeed * ball.ydir );
local xNew, yNew = ball.x + dx, ball.y + dy
local radius = ball.radius
if ( xNew > screenRight - radius or xNew < screenLeft + radius ) then
ball.xdir = -ball.xdir
end
if ( yNew > screenBottom - radius or yNew < screenTop + radius ) then
ball.ydir = -ball.ydir
end
ball:translate( dx, dy )
end
end
Runtime:addEventListener( "enterFrame", collection );
Может ли кто-нибудь помочь мне изменить изображения из круга в мои изображения balloon01.png,balloon02.png и balloon03.png в моей папке. также это ошибка, которую я получаю, когда добавляю ее в свою игру, включающую API раскадровки
level1.lua 157: попытка вызвать глобальный "newBall" (нулевое значение)
Я пытался опубликовать изображение, но потому что я новичок, я не могу. У меня есть код, который бросает мяч в сцену создания, кроме API раскадровки Corona SDK, спасибо...:0 за вашу помощь
1 ответ
Я обновил код. Просто попробуйте заменить весь ваш код следующим кодом:
local xpos,ypos = {},{}
local xdirection,ydirection = {},{}
local xMultiplier = {2.8,3.0,4.0} -- these arrays should contain the values for each objects
local yMultiplier = {1.0,2.2,5.5} -- these arrays should contain the values for each objects
local totalImages = 3 -- no. of images/object that you need in the scene
local circle = {}
local diameter = {50,30,20} -- these arrays should contain the values for each objects
for i=1,totalImages do
xpos[i] = display.contentWidth*0.5
ypos[i] = display.contentHeight*0.5
xdirection[i] = 1
ydirection[i] = 1
circle[i] = display.newImageRect("balloon0"..i..".png",diameter[i],diameter[i])
circle[i]:setFillColor(255,0,0,255)
end
local function animate(event)
for i=1,totalImages do
xpos[i] = xpos[i] + ( xMultiplier[i] * xdirection[i] )
ypos[i] = ypos[i] + ( yMultiplier[i] * ydirection[i] )
if (xpos[i] > display.contentWidth - 20 or xpos[i] < 20) then
xdirection[i] = xdirection[i] * -1;
end
if (ypos[i] > display.contentHeight - 20 or ypos[i] < 20) then
ydirection[i] = ydirection[i] * -1;
end
circle[i]:translate( xpos[i] - circle[i].x, ypos[i] - circle[i].y)
end
end
Runtime:addEventListener( "enterFrame", animate )
Примечание. Обязательно поместите следующие файлы изображений в ту же папку, где находится файл main.lua:
- balloon01.png
- balloon02.png
- balloon03.png
Продолжайте кодировать............:)