Hi everybody. Right now i’m coding a little shop app.
The money system is setted up and everything except one thing is looking fine. I’m using ICE wich i havnt use before, so im a bit of a newbie on that part. Anyhow, my issue is following:
When i click “Btn” and director has changed sceen to “Shop.lua” the ball and the text(that informs you how much money you got on your “account”) wont be “removed”. You can still se them on the other screen(wich has almmost no code on its lua file). I know that the Ball is a global object but i dont want to reset its state. If i change the “_G.Lvl = 2” to “_G.Lvl = 0” i wont see the ball on the shop screen but i cant see it on the MainScreen eighter. (Thats logic). Anyhow i know that this has something to do with Ice since i’ve coded a lot of test apps before and never had this issus until now(fitst time im using ice). So please tell me how to fix this.
Why wont the text remove?
Thanks in advance:)
//Philip
BTW: Here is my code
[lua] module(…, package.seeall)
function new()
local localGroup = display.newGroup()
require (“physics”)
require “ui”
require ( “ice” )
physics.start()
physics.setGravity(2)
display.setStatusBar( display.HiddenStatusBar )
local Background = display.newImage( “Background.png”)
Background.x = 512
Background.y = 384
local Grass = display.newImage( “Grass.png”)
Grass.x = 512
Grass.y = 704
physics.addBody (Grass, “static”, {bounce=0.0, density=1.0})
local Ground = display.newImage( “Ground.png”)
Ground.x = 512
Ground.y = 626
local MoneyBar = display.newImage( “MoneyBar.png”)
MoneyBar.x = 828
MoneyBar.y = 55
local moneys = ice:loadBox( “moneys” )
local GetMoneyFive = function( event )
moneys:increment( “cash”, 5 )
moneys:save()
end
local GetMoneySeven = function( event )
moneys:increment( “cash”, 7 )
moneys:save()
end
local GetMoneyTen = function( event )
moneys:increment( “cash”, 10 )
moneys:save()
end
_G.Lvl = 2
if _G.Lvl == 1 then
local RedChar = display.newImage (“Red_ball_Char.png”)
RedChar.x = display.contentWidth /2
RedChar.y = display.contentHeight /2
physics.addBody (RedChar, {bounce=0.6, density=1.0})
RedChar:addEventListener( “tap”, GetMoneyFive )
end
if _G.Lvl == 2 then
local GreenChar = display.newImage (“Green_ball_Char.png”)
GreenChar.x = display.contentWidth /2
GreenChar.y = display.contentHeight /2
physics.addBody (GreenChar, {bounce=0.6, density=1.0})
GreenChar:addEventListener( “tap”, GetMoneySeven )
end
if _G.Lvl == 3 then
local BlueChar = display.newImage (“Blue_ball_Char.png”)
BlueChar.x = display.contentWidth /2
BlueChar.y = display.contentHeight /2
physics.addBody (BlueChar, {bounce=0.6, density=1.0})
BlueChar:addEventListener( “tap”, GetMoneyTen )
end
MoneyS = display.newText( “0”, 0, 0, “Helvetica”, 60 )
MoneyS.x = MoneyBar.x
MoneyS.y = MoneyBar.y
local onEnterFrame = function( event )
MoneyS.text = moneys:retrieve( “cash” ) or 0
end
Runtime:addEventListener( “enterFrame”, onEnterFrame )
Btn = ui.newButton{
default = “ShopBtn.png”,
over = “ShopBtn_C.png”,
x = 102,
y = 708,
}
local function ShopS (event)
if event.phase == “ended” then
director:changeScene (“ShopScreen”, “fade”)
end
end
Btn:addEventListener (“touch”, ShopS)
localGroup:insert(Background)
localGroup:insert(Grass)
localGroup:insert(Ground)
localGroup:insert(Btn)
localGroup:insert(MoneyBar)
return localGroup
end
[import]uid: 119384 topic_id: 24074 reply_id: 324074[/import]