So I've been working on my app for quite awhile and like a lot of developers I neglected to watch how much code I was using and as a result it is extremely choppy and laggy. My game is simple: There are apples on a tree and they fall down the screen to an awaiting pig with a bucket. I have tried to optimize it but once you get to a higher level it just starts getting all choppy again. So a couple of questions...
1. Will Animation Engine work with iOS devices and be accepted by Apple so long as I follow their rules?
2. Before I buy AE I wanted to know if it could make my app run smoother? I posted some code so you know what I have currently...
Code: Select all
on initializeBalls
local tBallCounter, tBallID, tStartHeight, tStartRight, tLoc
lock screen
-- delete any old balls
if the number of items in gBallList > 0 then
repeat for each item tBallID in gBallList
try
delete tBallID
end try
end repeat
end if
put empty into gBallList
-- create the new apples
put item 2 of the loc of grc "grcStartField" into tLoc
repeat with tBallCounter = 1 to fld "fNumBalls"
# This clones one apple however many times I choose
clone img "BallTemplate"
put it into tBallID
put tBallID & comma after gBallList
set the width of tBallID to fld "fBallSize"
set the height of tBallID to fld "fBallSize"
# This makes a "Box" of constraints
put random(220) + 10 & comma & random(200) + 20 into tLoc
set the loc of img "BallTemplate" to tLoc
end repeat
delete the last char of gBallList
unlock screen
end initializeBalls
on dropTheBalls
local tTimeSpan, tBallID, tBallNum, tTempBallList
lock screen
put fld "fDropRate" into tTimeSpan
put gBallList into tTempBallList
unlock screen
repeat the number of items in gBallList times
put random(the number of items in tTempBallList) into tBallNum
put item tBallNum of tTempBallList into tBallID
send "dropMe" to tBallID in tTimeSpan seconds
delete item tBallNum of tTempBallList
add fld "fDropRate" to tTimeSpan
end repeat
end dropTheBalls
And this is the script for the apples when they drop. I think that one of my problems is that this is run EVERY time an apple drops. I've wondered if there was a way you could make a central location that you could store you custom handler and then call it in the app any where you want.
Code: Select all
global gBucket
on dropMe
local tXPos, tYTarget
add 1 to fld "fBallsDropped"
put item 1 of the loc of me into tXPos
put item 2 of the loc of grc "grcBucketField" into tYTarget
move me to tXPos,tYTarget without waiting
set the layer of img "BallTemplate" to bottom
end dropMe
on moveStopped
if pointIntersect(the loc of me,the rect of img "Pig") then
add 1 to fld "fBallsCaught"
add 1 to fld "fBallsCaught2"
hide me
play specialFolderPath("engine") & "/soundFormats/bite.aif"
end if
hide me
end moveStopped
function pointIntersect pPoint,pRect
split pPoint by comma
split pRect by comma
return ((pRect[1] <= pPoint[1]) and (pPoint[1] <= pRect[3]) and (pRect[2] <= pPoint[2]) and (pPoint[2] <= pRect[4]))
end pointIntersect
Thank you for taking the time to read it. I know it's a long post but I know you'd probably ask for sample code anyway.
Crossing my fingers,
Danny