Corona SDK
Animation1
Viewing the sample code assumes you have read and agree to the license agreement.
1 -- 2 -- Abstract: Bouncing ball (function listener) sample app 3 -- 4 -- Version: 1.0 5 -- 6 -- Disclaimer: IMPORTANT: This ANSCA software is supplied to you by ANSCA Inc. 7 -- ("ANSCA") in consideration of your agreement to the following terms, and your 8 -- use, installation, modification or redistribution of this ANSCA software 9 -- constitutes acceptance of these terms. If you do not agree with these terms, 10 -- please do not use, install, modify or redistribute this ANSCA software. 11 -- 12 -- In consideration of your agreement to abide by the following terms, and subject 13 -- to these terms, ANSCA grants you a personal, non-exclusive license, under 14 -- ANSCA's copyrights in this original ANSCA software (the "ANSCA Software"), to 15 -- use, reproduce, modify and redistribute the ANSCA Software, with or without 16 -- modifications, in source and/or binary forms; provided that if you redistribute 17 -- the ANSCA Software in its entirety and without modifications, you must retain 18 -- this notice and the following text and disclaimers in all such redistributions 19 -- of the ANSCA Software. 20 -- Neither the name, trademarks, service marks or logos of ANSCA Inc. may be used 21 -- to endorse or promote products derived from the ANSCA Software without specific 22 -- prior written permission from ANSCA. Except as expressly stated in this notice, 23 -- no other rights or licenses, express or implied, are granted by ANSCA herein, 24 -- including but not limited to any patent rights that may be infringed by your 25 -- derivative works or by other works in which the ANSCA Software may be 26 -- incorporated. 27 -- 28 -- The ANSCA Software is provided by ANSCA on an "AS IS" basis. ANSCA MAKES NO 29 -- WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 30 -- WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 31 -- PURPOSE, REGARDING THE ANSCA SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 32 -- COMBINATION WITH YOUR PRODUCTS. 33 -- 34 -- IN NO EVENT SHALL ANSCA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 35 -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 36 -- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 -- ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 38 -- DISTRIBUTION OF THE ANSCA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 39 -- CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 40 -- ANSCA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 -- 42 -- Copyright (C) 2009 ANSCA Inc. All Rights Reserved. 43 44 -- Demonstrates how to use function listeners. In general, it's easier to code 45 -- up using function listeners and is suited for very simple apps. For more 46 -- complex apps, use table listeners --- trust me, it's worth it! 47 48 local radius = 20 49 50 local xdirection = 1 51 local ydirection = 1 52 53 local xspeed = 2.8 54 local yspeed = 2.2 55 56 local xpos = display.stageWidth*0.5; 57 local ypos = display.stageHeight*0.5; 58 local circle = display.newCircle( xpos, ypos, radius ); 59 circle:setFillColor(255,0,0,255); 60 61 local function animate(event) 62 xpos = xpos + ( xspeed * xdirection ); 63 ypos = ypos + ( yspeed * ydirection ); 64 65 if (xpos > display.stageWidth - radius or xpos < radius) then 66 xdirection = xdirection * -1; 67 end 68 if (ypos > display.stageHeight - radius or ypos < radius) then 69 ydirection = ydirection * -1; 70 end 71 72 circle:translate( xpos - circle.x, ypos - circle.y) 73 end 74 75 76 Runtime:addEventListener( "enterFrame", animate ); 77
| Attachment | Size |
|---|---|
| Animation1.zip | 24.29 KB |