Skip to content
Browse files

code cleaning and some fixes

  • Loading branch information...
1 parent 2141629 commit 287b8b878a31e6512c53e0cae124723acfbaadbc @MattiaFortunati MattiaFortunati committed May 22, 2012
View
2 main.lua
@@ -31,7 +31,7 @@ end --]]
-- Anim
--require("rapanui-samples/anim/rn-anim")
--- require("rapanui-samples/anim/rn-anim2")
+--require("rapanui-samples/anim/rn-anim2")
-- Basics
View
10 rapanui-samples/anim/rn-anim.lua
@@ -39,10 +39,10 @@ function onEndS4()
end
-liliaChar:newSequence("walkFront", { 0, 1, 2, 3, 2 }, 6, 2, onEndS1)
-liliaChar:newSequence("walkBack", { 0, 8, 9, 10, 9 }, 6, 2, onEndS2)
-liliaChar:newSequence("walkLeft", { 0, 4, 5, 6, 5 }, 6, 2, onEndS3)
-liliaChar:newSequence("walkRight", { 0, 6, 7, 8, 7 }, 6, 2, onEndS4)
+liliaChar:newSequence("walkFront", { 1, 2, 3, 2 }, 6, 2, onEndS1)
+liliaChar:newSequence("walkBack", { 10, 11, 12, 11 }, 6, 2, onEndS2)
+liliaChar:newSequence("walkLeft", { 4, 5, 6, 5 }, 6, 2, onEndS3)
+liliaChar:newSequence("walkRight", { 7, 8, 9, 8 }, 6, 2, onEndS4)
liliaChar:play("walkFront")
liliaChar.frame = 1
@@ -67,7 +67,7 @@ function onEndSEktor()
end
-ektorChar:newSequence("walkFront", { 0, 1, 2, 3, 2 }, 6, 10, onEndSEktor)
+ektorChar:newSequence("walkFront", { 1, 2, 3, 2 }, 6, 10, onEndSEktor)
ektorChar.x = 200
ektorChar.y = 250
View
10 rapanui-samples/anim/rn-anim2.lua
@@ -41,12 +41,12 @@ end
--physical animation with many sequences
--newAnim(file,sizeX,sizeY[,posx,posy,scaleX,scaleY])
-char = RNFactory.createAnim("images/char.png", 42, 32, 100, 200, 0.27, 0.5)
+char = RNFactory.createAnim("images/char.png", 42, 32, 100, 300, 2, 3)
--newSequence(name,frameOrder,speed,repeatTimes,onStopFunction)
-char:newSequence("walkFront", { 0, 7, 8, 9 }, 6, 1, onEndS1)
-char:newSequence("walkBack", { 0, 1, 2, 3 }, 6, 10, onEndS2)
-char:newSequence("walkLeft", { 0, 4, 5, 6 }, 6, 10, onEndS3)
-char:newSequence("walkRight", { 0, 10, 11, 12 }, 6, 10, onEndS4)
+char:newSequence("walkFront", { 7, 8, 9 }, 6, 10, onEndS1)
+char:newSequence("walkBack", { 1, 2, 3 }, 6, 10, onEndS2)
+char:newSequence("walkLeft", { 4, 5, 6 }, 6, 10, onEndS3)
+char:newSequence("walkRight", { 10, 11, 12 }, 6, 10, onEndS4)
char:play("walkFront")
View
2 rapanui-samples/atlas/rn-atlas-texture-packer.lua
@@ -29,5 +29,5 @@ RNFactory.createImage("tile3.png", { left = 200, top = 100 })
--in fact images created from atlas are animations.
local img = RNFactory.createImage("drink.png", { top = 250, left = 150 })
--indexes are images in atlas ordered as exported from Texture Packer
-img:newSequence("seq", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 3, 5)
+img:newSequence("seq", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 3, 5)
img:play("seq")
View
4 rapanui-samples/director/rn-director-basic.lua
@@ -41,7 +41,7 @@ director:setTime(1000)
--FADE IN TEST
---director:showScene("rapanui-samples/director/scene1","fade")
+director:showScene("rapanui-samples/director/scene1","fade")
--FADE OUT TEST
@@ -55,7 +55,7 @@ director:setTime(1000)
--SLIDE TO LEFT IN TEST
-director:showScene("rapanui-samples/director/scene1", "slidetoleft")
+--director:showScene("rapanui-samples/director/scene1", "slidetoleft")
--SLIDE TO LEFT OUT TEST
View
80 rapanui-sdk/RNFactory.lua
@@ -205,41 +205,6 @@ function RNFactory.createImageFromMoaiImage(moaiImage, params)
return image
end
-function RNFactory.createImage2(image, sizex, sizey)
- local o = RNObject:new()
- local o, deck = o:initWithImage2(image, sizex, sizey)
-
-
- local parentGroup = RNFactory.mainGroup
-
- RNFactory.screen:addRNObject(o)
-
- if parentGroup ~= nil then
- parentGroup:insert(o)
- end
-
-
- return o, deck
-end
-
-function RNFactory.createAnim2(image, sizex, sizey, tilex, tiley, posx, posy, scalex, scaley)
- local o = RNObject:new()
- local o, deck = o:initWithAnim2(image, sizex, sizey, tilex, tiley, scalex, scaley)
-
- o.x = posx
- o.y = posy
-
- local parentGroup = RNFactory.mainGroup
-
- RNFactory.screen:addRNObject(o)
-
- if parentGroup ~= nil then
- parentGroup:insert(o)
- end
-
-
- return o, deck
-end
function RNFactory.createMoaiImage(filename)
local image = MOAIImage.new()
@@ -388,51 +353,6 @@ function RNFactory.createText(text, params)
end
-function RNFactory.createTextOld(text, params)
-
- local top, left, size, font, height, width, alignment
-
- font = "arial-rounded"
- size = 15
- alignment = MOAITextBox.CENTER_JUSTIFY
- --LEFT_JUSTIFY, CENTER_JUSTIFY or RIGHT_JUSTIFY.
-
- if (params ~= nil) then
- if (params.top ~= nil) then
- top = params.top
- end
-
- if (params.left ~= nil) then
- left = params.left
- end
-
- if (params.font ~= nil) then
- font = params.font
- end
-
- if (params.size ~= nil) then
- size = params.size
- end
-
- if (params.height ~= nil) then
- height = params.height
- end
-
- if (params.width ~= nil) then
- width = params.width
- end
-
- if (params.alignment ~= nil) then
- alignment = params.alignment
- end
- end
-
- local RNText = RNText:new()
- RNText:initWithText(text, font, size, left, top, width, height, alignment)
- RNFactory.screen:addRNObject(RNText)
- RNFactory.mainGroup:insert(RNText)
- return RNText
-end
function RNFactory.createRect(x, y, width, height, params)
local parentGroup, top, left
View
176 rapanui-sdk/RNObject.lua
@@ -462,15 +462,6 @@ function RNObject:loadCopyRect(src, params)
end
---- Initializes the object with the given image path
--- @param image the path of the image to use
-function RNObject:initWith(image)
- self.visible = true
- self.childrenSize = 0
-
- self.alpha = 1
- self:loadImage(image)
-end
function RNObject:initWithMoaiImage(moaiImage)
@@ -505,34 +496,6 @@ function RNObject:initWithMoaiImage(moaiImage)
end
-function RNObject:loadImage(image)
- self.name = image
-
- self.gfxQuad = MOAIGfxQuad2D.new()
-
- self.image = MOAIImage.new()
- self.image:load(image, MOAIImage.TRUECOLOR + MOAIImage.PREMULTIPLY_ALPHA)
-
- self.originalWidth, self.originalHeight = self.image:getSize()
-
- self.image = self.image:padToPow2()
- self.gfxQuad:setTexture(self.image)
-
- self.pow2Width, self.pow2Height = self.image:getSize()
-
- self.prop = MOAIProp2D.new()
-
- local u = self.originalWidth / self.pow2Width
- local v = self.originalHeight / self.pow2Height
-
- self.gfxQuad:setUVRect(0, 0, u, v)
-
-
- self.prop:setDeck(self.gfxQuad)
- self.gfxQuad:setRect(-self.originalWidth / 2, -self.originalHeight / 2, (self.originalWidth) / 2, (self.originalHeight) / 2)
- self.prop:setPriority(1)
-end
-
function RNObject:initWithImage2(image)
local deck = image
@@ -717,14 +680,6 @@ function RNObject:getDebugName()
end
-function RNObject:initAnimWith(image, sx, sy, scaleX, scaleY)
- self.visible = true
- self.childrenSize = 0
-
- self.alpha = 1
- self:loadAnim(image, sx, sy, scaleX, scaleY)
-end
-
function RNObject:setIDInGroup(id)
self.idInGroup = id
@@ -739,109 +694,6 @@ function RNObject:setIDInScreen(id)
self.idInScreen = id
end
-
-function RNObject:loadAnim(image, sx, sy, scaleX, scaleY)
- self.name = image
-
-
- self.tileDeck = MOAITileDeck2D.new()
-
-
- self.image = MOAIImage.new()
- self.image:load(image, MOAIImage.TRUECOLOR + MOAIImage.PREMULTIPLY_ALPHA)
- -- self.image = self.image:padToPow2()
- self.originalWidth, self.originalHeight = self.image:getSize()
-
-
- self.image = self.image:padToPow2()
-
-
- local oWnotPadded = self.originalWidth
- local oHnotPadded = self.originalHeight
-
-
- self.originalWidth, self.originalHeight = self.image:getSize()
-
-
- self.tileDeck:setTexture(self.image)
- local px = self.originalWidth / sx
- local py = self.originalHeight / sy
- --self.tileDeck:setSize(number width, number height [, number cellWidth, number cellHeight, number xOff, number yOff, number tileWidth, number tileHeight ] )
- self.tileDeck:setSize(px, py, 1 / px, 1 / py, 0, 0, 1 / px, 1 / py)
- self.prop = MOAIProp2D.new()
- self.prop:setIndex(1)
-
- self.prop:setDeck(self.tileDeck)
-
- local oW = self.originalWidth
- local oH = self.originalHeight
-
- --self.tileDeck:setRect(-sx * scaleX / 2, sy * scaleY / 2, sx * scaleX / 2, -sy * scaleY / 2)
- self.tileDeck:setRect(-sx * scaleX, sy * scaleY, sx * scaleX, -sy * scaleY)
- self.originalWidth = sx * scaleX * 2
- self.originalHeight = sy * scaleY * 2
- self.scaleX = scaleX
- self.scaleY = scaleY
- self.sizex = sx
- self.sizey = sy
- self.isAnim = true
- self.frameNumberTotal = oW / sx * oH / sy
-
- --we check for default sequence frame Order
- local defaultFrameOrder = {}
- for j = 1, self.frameNumberTotal, 1 do defaultFrameOrder[j] = j end
- --we create a new sequence
- self:newSequence("default", defaultFrameOrder, 12, 1, nil)
- --and set it as current
- self.currentSequence = "default"
- self.frame = 1
- self.tmplistener = RNListeners:addEventListener("enterFrame", self)
-end
-
-function RNObject:enterFrame(event)
- --takes self as himself
- self = self.source
- --uptades counter
- self.animCounter = self.animCounter + 1
- --if it's not paused
- if self.pause == false then
- --we check for the right sequence to play
- local rightSequenceToPlay = nil
- if self.sequenceList ~= nil then
- for i = 1, table.getn(self.sequenceList), 1 do
- if self.sequenceList[i].name == self.currentSequence then rightSequenceToPlay = i end
- end
- end
- local rightSequence = self.sequenceList[rightSequenceToPlay]
- --if the counter reachs the sequence speed
- if self.animCounter == rightSequence.speed then
- --we check for the next sequence's frame to play
- local nextSequenceFrame
- if rightSequence.frameOrder[rightSequence.currentFrame + 1] ~= nil then
- nextSequenceFrame = rightSequence.frameOrder[rightSequence.currentFrame + 1]
- rightSequence.currentFrame = rightSequence.currentFrame + 1
- else
- nextSequenceFrame = rightSequence.frameOrder[1]
- rightSequence.currentFrame = 1
- end
- --we upgrade the sequence repeated times, if it is not -1 (infinite loop)
- if rightSequence.reapeatTimes ~= -1 then rightSequence.timeRepeated = rightSequence.timeRepeated + 1 end
- --the object goes to the right frame
- self.frame = nextSequenceFrame
- --the counter goes back to 0
- self.animCounter = 0
- --if we have repeated the sequence enough (-1 to stop on the last frame)
- if rightSequence.timeRepeated == table.getn(rightSequence.frameOrder) * rightSequence.repeatTimes - 1 then
- self.pause = true
- if rightSequence.onStop ~= nil then
- local funct = rightSequence.onStop
- funct()
- end
- end
- end
- end
-end
-
function RNObject:animate(keyframe, executed, value)
--print("keyframe " .. keyframe)
--print("executed " .. executed)
@@ -860,19 +712,21 @@ function RNObject:animate(keyframe, executed, value)
self.frame = rightSequence.frameOrder[keyframe]
--if we meet execution times
--print(executed, rightSequence.repeatTimes, #rightSequence.frameOrder)
- if executed >= rightSequence.repeatTimes then
- --print("stopped")
- --stop and deallocate timer
- self.timer:stop()
- self.timer = nil
- --get right sequence from list
- local rightSequence = self.sequenceList[rightSequenceToPlay]
- --call onEnd function
- if rightSequence.onStop ~= nil then
- local funct = rightSequence.onStop
- funct()
- end
- --stops animation
+ if rightSequence.repeatTimes ~= -1 then
+ if executed >= rightSequence.repeatTimes then
+ --print("stopped")
+ --stop and deallocate timer
+ self.timer:stop()
+ self.timer = nil
+ --get right sequence from list
+ local rightSequence = self.sequenceList[rightSequenceToPlay]
+ --call onEnd function
+ if rightSequence.onStop ~= nil then
+ local funct = rightSequence.onStop
+ funct()
+ end
+ --stops animation
+ end
end
end
View
31 rapanui-sdk/RNText.lua
@@ -65,37 +65,6 @@ function RNText:new(o)
end
-function RNText:initWithText(text, font, size, x, y, width, height, alignment)
- self.charcodes = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,:;!?()&/-'
-
- if font ~= nil then
- self.fontName = font
- end
-
- self.font = MOAIFont.new()
- self.font:loadFromTTF(self.fontName .. ".TTF", self.charcodes, size, 163)
-
- self.locatingMode = CENTERED_MODE
- self.text = text
-
- self.name = text
- self.visible = true
-
- self.textbox = MOAITextBox.new()
- self.prop = self.textbox
-
- self.text = text
-
-
- self.textbox:setString(self.text)
- self.textbox:setFont(self.font)
- self.textbox:setTextSize(size, 163)
- self.textbox:setRect(x, y, x + width, y + height)
- self.textbox:setAlignment(alignment)
-
- self:setTextColor(255, 255, 255)
-end
-
function RNText:initWithText2(text, font, size, x, y, width, height, alignment)
self.charcodes = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .,:;!?()&/-'

0 comments on commit 287b8b8

Please sign in to comment.
Something went wrong with that request. Please try again.