android - how to animate a ball in Corona sdk -


hi need code. trying make 3 ball bounce around animating it. i found code code in corona sdk sample code. try change image circle image have in folder luck wont work. using story board api need new corona sdk.

this sample code

this code works me want add multiple balloons bounce around in own direction , bounce in each other , change direction. kinda stuck on can :)....................

here code ask sorry taking long

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 , add new balls array _,item in ipairs( params )     local ball = newball( item )     collection[ #collection + 1 ] = ball end  -- current edges of visible screen (accounting areas cropped "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 )     _,ball in ipairs( collection )         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 )             ball.xdir = -ball.xdir         end         if ( ynew > screenbottom - radius or ynew < screentop + radius )             ball.ydir = -ball.ydir         end          ball:translate( dx, dy )     end end  runtime:addeventlistener( "enterframe", collection ); 

can me change images circle balloon01.png ,balloon02.png , balloon03.png images in folder. error when add game include story board api

level1.lua 157:attempt call global "newball" (a nil value)

i trying post image because new can't. have code crate ball in create scene that's apart of corona sdk story board api ...:0

i've updated code. try replacing code following code:

local xpos,ypos = {},{} local xdirection,ydirection = {},{} local xmultiplier = {2.8,3.0,4.0}     -- these arrays should contain values each objects local ymultiplier = {1.0,2.2,5.5}     -- these arrays should contain values each objects local totalimages = 3     -- no. of images/object need in scene local circle = {} local diameter = {50,30,20}   -- these arrays should contain values each objects  i=1,totalimages     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)     i=1,totalimages       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)           xdirection[i] = xdirection[i] * -1;       end       if (ypos[i] > display.contentheight - 20 or ypos[i] < 20)           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 ) 

note: make sure place following image files in same folder main.lua resides:

  1. balloon01.png
  2. balloon02.png
  3. balloon03.png

keep coding............ :)


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -