-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain_test.lua
More file actions
68 lines (60 loc) · 2.36 KB
/
main_test.lua
File metadata and controls
68 lines (60 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--- ************************************************************************************************************************************************************************
---
--- Name : main_test.lua
--- Purpose : Bullying test of BitmapString class
--- Created: 23 May 2014
--- Author: Paul Robson (paul@robsons.org.uk)
--- License: MIT
---
--- ************************************************************************************************************************************************************************
display.setStatusBar(display.HiddenStatusBar)
fm = require("system.fontmanager")
local marker = display.newBitmapText("Test",160,240,"retrofont",40)
local stringList = {}
local count = 10000
local maxStrings = 500
local fontList = { "retrofont","demofont","font2","testfont"}
local function tidyUp()
for _,bms in pairs(stringList) do bms:remove() end
marker:remove(true)
print("Ok completed.")
end
local function sillyModifier(modifier,cPos,info)
modifier.xOffset = math.random(-10,10)
modifier.yOffset = math.random(-10,10)
modifier.xScale = math.random(-10,10)/5 + 1
modifier.yScale = math.random(-10,10)/5 + 1
modifier.alpha = math.random(0,10)/20+0.5
modifier.rotation = math.random(0,360)
end
local function getX() return math.random(0,320) end
local function getY() return math.random(0,480) end
local function getFont() return fontList[math.random(1,#fontList)] end
local function getFontSize() return math.random(1,200) end
local function getText()
local str = ""
local size = math.random(1,32)
for i = 1,size do str = str .. string.char(math.random(32,96)) end
return str
end
Runtime:addEventListener("enterFrame",function(e)
count = count - 1
if count == 0 then tidyUp() end
if count > 0 then
if count % 100 == 0 then print(count) end
local index = math.random(1,maxStrings)
if stringList[index] == nil then
stringList[index] = display.newBitmapText(getText(),getX(),getY(),getFont(),getFontSize())
stringList[index]:setModifier(sillyModifier):animate()
stringList[index]:setAnchor(math.random(0,2)/2,math.random(0,2)/2)
end
if math.random(1,3) == 1 then
local s = stringList[index]
s:setText(getText()):moveTo(getX(),getY()):setFont(getFont(),getFontSize()):setDirection(math.random(0,3)*90)
end
if math.random(1,5) == 1 then
stringList[index]:removeSelf()
stringList[index] = nil
end
end
end)