Merge pull request #5160 from samuele3hu/developBugFix

fix:Update the some test cases for lua
This commit is contained in:
James Chen 2014-01-22 01:21:50 -08:00
commit 1b89a058fa
11 changed files with 147 additions and 146 deletions

View File

@ -29,6 +29,12 @@ function TextureCacheDeprecated.destroyInstance(self)
end
rawset(cc.TextureCache,"destroyInstance",TextureCacheDeprecated.destroyInstance)
function TextureCacheDeprecated.dumpCachedTextureInfo(self)
deprecatedTip("self:dumpCachedTextureInfo","self:getCachedTextureInfo")
return print(self:getCachedTextureInfo())
end
rawset(cc.TextureCache,"dumpCachedTextureInfo",TextureCacheDeprecated.dumpCachedTextureInfo)
local CCTextureCacheDeprecated = { }
function CCTextureCacheDeprecated.sharedTextureCache()
deprecatedTip("CCTextureCache:sharedTextureCache","CCTextureCache:getInstance")

View File

@ -15,7 +15,7 @@ local function IntervalLayer()
local s = cc.Director:getInstance():getWinSize()
-- sun
local sun = cc.ParticleSun:create()
sun:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
sun:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png"))
sun:setPosition( cc.p(VisibleRect:rightTop().x-32,VisibleRect:rightTop().y-32) )
sun:setTotalParticles(130)

View File

@ -299,7 +299,7 @@ local function shouldNotCrash(dt)
-- if the node has timers, it crashes
local explosion = cc.ParticleSun:create()
explosion:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
explosion:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png"))
explosion:setPosition(s.width / 2, s.height / 2)
@ -369,7 +369,7 @@ local function StressTest2()
sublayer:addChild(sp1, 1)
local fire = cc.ParticleFire:create()
fire:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
fire:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png"))
fire = tolua.cast(fire, "cc.Node")
fire:setPosition(80, s.height / 2 - 50)

View File

@ -378,7 +378,7 @@ local function DemoFlower()
emitter = cc.ParticleFlower:create()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_stars1))
setEmitterPosition()
@ -396,7 +396,7 @@ local function DemoGalaxy()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
setEmitterPosition()
@ -414,7 +414,7 @@ local function DemoFirework()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_stars1))
setEmitterPosition()
@ -432,7 +432,7 @@ local function DemoSpiral()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
setEmitterPosition()
@ -450,7 +450,7 @@ local function DemoSun()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
setEmitterPosition()
@ -468,7 +468,7 @@ local function DemoMeteor()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
setEmitterPosition()
@ -486,7 +486,7 @@ local function DemoFire()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
local pos_x, pos_y = emitter:getPosition()
emitter:setPosition(pos_x, 100)
@ -503,7 +503,7 @@ local function DemoSmoke()
emitter = cc.ParticleSmoke:create()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
local pos_x, pos_y = emitter:getPosition()
emitter:setPosition(pos_x, 100)
@ -523,7 +523,7 @@ local function DemoExplosion()
-- emitter:retain()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_stars1))
emitter:setAutoRemoveOnFinish(true)
@ -566,7 +566,7 @@ local function DemoSnow()
emitter:setEmissionRate(emitter:getTotalParticles() / emitter:getLife())
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_snow))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_snow))
setEmitterPosition()
@ -587,7 +587,7 @@ local function DemoRain()
emitter:setPosition(pos_x, pos_y - 100)
emitter:setLife(4)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
setEmitterPosition()
@ -605,7 +605,7 @@ local function DemoBigFlower()
background:addChild(emitter, 10)
----emitter:release() -- win32 : use this line or remove this line and use autorelease()
emitter:setTexture( cc.TextureCache:getInstance():addImage(s_stars1) )
emitter:setTexture( cc.Director:getInstance():getTextureCache():addImage(s_stars1) )
emitter:setDuration(-1)
-- gravity
@ -674,7 +674,7 @@ local function DemoRotFlower()
background:addChild(emitter, 10)
----emitter:release() -- win32 : Remove this line
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars2))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_stars2))
-- duration
emitter:setDuration(-1)
@ -792,7 +792,7 @@ local function DemoModernArt()
emitter:setEndSizeVar(8.0)
-- texture
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
-- additive
emitter:setBlendAdditive(false)
@ -814,7 +814,7 @@ local function DemoRing()
background:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_stars1))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_stars1))
emitter:setLifeVar(0)
emitter:setLife(10)
emitter:setSpeed(100)
@ -847,14 +847,14 @@ local function ParallaxParticle()
emitter = cc.ParticleFlower:create()
-- emitter:retain()
emitter:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
p1:addChild(emitter, 10)
emitter:setPosition(250, 200)
local par = cc.ParticleSun:create()
p2:addChild(par, 10)
par:setTexture(cc.TextureCache:getInstance():addImage(s_fire))
par:setTexture(cc.Director:getInstance():getTextureCache():addImage(s_fire))
local move = cc.MoveBy:create(4, cc.p(300,0))
local move_back = move:reverse()
@ -897,7 +897,7 @@ local function RadiusMode1()
emitter = cc.ParticleSystemQuad:createWithTotalParticles(200)
layer:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage("Images/stars-grayscale.png"))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/stars-grayscale.png"))
-- duration
emitter:setDuration(cc.PARTICLE_DURATION_INFINITY)
@ -967,7 +967,7 @@ local function RadiusMode2()
emitter = cc.ParticleSystemQuad:createWithTotalParticles(200)
layer:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage("Images/stars-grayscale.png"))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/stars-grayscale.png"))
-- duration
emitter:setDuration(cc.PARTICLE_DURATION_INFINITY )
@ -1036,7 +1036,7 @@ local function Issue704()
emitter = cc.ParticleSystemQuad:createWithTotalParticles(100)
layer:addChild(emitter, 10)
emitter:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
emitter:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png"))
-- duration
emitter:setDuration(cc.PARTICLE_DURATION_INFINITY)
@ -1129,7 +1129,7 @@ local function Issue870()
background = nil
local system = cc.ParticleSystemQuad:create("Particles/SpinningPeas.plist")
system:setTextureWithRect(cc.TextureCache:getInstance():addImage("Images/particles.png"), cc.rect(0,0,32,32))
system:setTextureWithRect(cc.Director:getInstance():getTextureCache():addImage("Images/particles.png"), cc.rect(0,0,32,32))
layer:addChild(system, 10)
emitter = system
@ -1151,7 +1151,7 @@ local function MultipleParticleSystems()
layer:removeChild(background, true)
background = nil
cc.TextureCache:getInstance():addImage("Images/particles.png")
cc.Director:getInstance():getTextureCache():addImage("Images/particles.png")
for i = 0, 4 do
local particleSystem = cc.ParticleSystemQuad:create("Particles/SpinningPeas.plist")

View File

@ -80,7 +80,7 @@ local function initWithSubTest(nSubTest, p)
parent = p
batchNode = nil
local mgr = cc.TextureCache:getInstance()
local mgr = cc.Director:getInstance():getTextureCache()
-- remove all texture
mgr:removeTexture(mgr:addImage("Images/grossinis_sister1.png"))
mgr:removeTexture(mgr:addImage("Images/grossini_dance_atlas.png"))

View File

@ -731,8 +731,8 @@ local function runParticleTest()
pNewScene:removeChildByTag(ParticleTestParam.kTagParticleSystem, true)
--remove the "fire.png" from the TextureCache cache.
local pTexture = cc.TextureCache:getInstance():addImage("Images/fire.png")
cc.TextureCache:getInstance():removeTexture(pTexture)
local pTexture = cc.Director:getInstance():getTextureCache():addImage("Images/fire.png")
cc.Director:getInstance():getTextureCache():removeTexture(pTexture)
local pParticleSystem = cc.ParticleSystemQuad:createWithTotalParticles(nQuantityParticles)
if 1 == nSubtestNumber then
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
@ -752,7 +752,7 @@ local function runParticleTest()
end
if nil ~= pParticleSystem then
pParticleSystem:setTexture(cc.TextureCache:getInstance():addImage("Images/fire.png"))
pParticleSystem:setTexture(cc.Director:getInstance():getTextureCache():addImage("Images/fire.png"))
end
pNewScene:addChild(pParticleSystem, 0, ParticleTestParam.kTagParticleSystem)
@ -1203,7 +1203,7 @@ local function runSpriteTest()
*12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
]]--
--purge textures
local pMgr = cc.TextureCache:getInstance()
local pMgr = cc.Director:getInstance():getTextureCache()
--[mgr removeAllTextures]
pMgr:removeTexture(pMgr:addImage("Images/grossinis_sister1.png"))
pMgr:removeTexture(pMgr:addImage("Images/grossini_dance_atlas.png"))
@ -1352,7 +1352,7 @@ local function runTextureTest()
local function PerformTestsPNG(strFileName)
local time
local pTexture = nil
local pCache = cc.TextureCache:getInstance()
local pCache = cc.Director:getInstance():getTextureCache()
print("RGBA 8888")
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
pTexture = pCache:addImage(strFileName)

View File

@ -25,7 +25,7 @@ local function RenderTextureSave()
local pImage = m_pTarget:newImage()
local tex = cc.TextureCache:getInstance():addUIImage(pImage, png)
local tex = cc.Director:getInstance():getTextureCache():addUIImage(pImage, png)
pImage:release()
@ -44,7 +44,7 @@ local function RenderTextureSave()
if event == "exit" then
m_pBrush:release()
m_pTarget:release()
cc.TextureCache:getInstance():removeUnusedTextures()
cc.Director:getInstance():getTextureCache():removeUnusedTextures()
end
end

View File

@ -7,10 +7,10 @@ local originCreateLayer = createTestLayer
local function createTestLayer(title, subtitle)
local ret = originCreateLayer(title, subtitle)
Helper.titleLabel:setTag(kTagLabel)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
local col = cc.LayerColor:create(cc.c4b(128,128,128,255))
ret:addChild(col, -10)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
--------------------------------------------------------------------
@ -26,7 +26,7 @@ local function TextureTIFF()
local img = cc.Sprite:create("Images/test_image.tiff")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -43,7 +43,7 @@ local function TexturePNG()
local img = cc.Sprite:create("Images/test_image.png")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -59,7 +59,7 @@ local function TextureJPEG()
local img = cc.Sprite:create("Images/test_image.jpeg")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -75,7 +75,7 @@ local function TextureWEBP()
local img = cc.Sprite:create("Images/test_image.webp")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -89,12 +89,12 @@ local function TextureMipMap()
"Left image uses mipmap. Right image doesn't")
local s = cc.Director:getInstance():getWinSize()
local texture0 = cc.TextureCache:getInstance():addImage(
local texture0 = cc.Director:getInstance():getTextureCache():addImage(
"Images/grossini_dance_atlas.png")
texture0:generateMipmap()
texture0:setTexParameters(gl.LINEAR_MIPMAP_LINEAR, gl.LINEAR, gl.CLAMP_TO_EDGE, gl.CLAMP_TO_EDGE)
local texture1 = cc.TextureCache:getInstance():addImage(
local texture1 = cc.Director:getInstance():getTextureCache():addImage(
"Images/grossini_dance_atlas_nomipmap.png")
local img0 = cc.Sprite:createWithTexture(texture0)
@ -115,7 +115,7 @@ local function TextureMipMap()
img0:runAction(cc.RepeatForever:create(cc.Sequence:create(scale1, sc_back)))
img1:runAction(cc.RepeatForever:create(cc.Sequence:create(scale2, sc_back2)))
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -154,7 +154,7 @@ local function TexturePVRMipMap()
imgMipMap:runAction(cc.RepeatForever:create(cc.Sequence:create(scale1, sc_back)))
img:runAction(cc.RepeatForever:create(cc.Sequence:create(scale2, sc_back2)))
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -188,7 +188,7 @@ local function TexturePVRMipMap2()
imgMipMap:runAction(cc.RepeatForever:create(cc.Sequence:create(scale1, sc_back)))
img:runAction(cc.RepeatForever:create(cc.Sequence:create(scale2, sc_back2)))
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -211,7 +211,7 @@ local function TexturePVR2BPP()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -234,7 +234,7 @@ local function TexturePVR()
else
cclog("This test is not supported.")
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -258,7 +258,7 @@ local function TexturePVR4BPP()
else
cclog("This test is not supported in cocos2d-mac")
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -277,7 +277,7 @@ local function TexturePVRRGBA8888()
local img = cc.Sprite:create("Images/test_image_rgba8888.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -300,7 +300,7 @@ local function TexturePVRBGRA8888()
else
cclog("BGRA8888 images are not supported")
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -318,7 +318,7 @@ local function TexturePVRRGBA5551()
local img = cc.Sprite:create("Images/test_image_rgba5551.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -336,7 +336,7 @@ local function TexturePVRRGBA4444()
local img = cc.Sprite:create("Images/test_image_rgba4444.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -355,7 +355,7 @@ local function TexturePVRRGBA4444GZ()
local img = cc.Sprite:create("Images/test_image_rgba4444.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -374,7 +374,7 @@ local function TexturePVRRGBA4444CCZ()
local img = cc.Sprite:create("Images/test_image_rgba4444.pvr.ccz")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -392,7 +392,7 @@ local function TexturePVRRGB565()
local img = cc.Sprite:create("Images/test_image_rgb565.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -408,7 +408,7 @@ local function TexturePVRRGB888()
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -426,7 +426,7 @@ local function TexturePVRA8()
local img = cc.Sprite:create("Images/test_image_a8.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -444,7 +444,7 @@ local function TexturePVRI8()
local img = cc.Sprite:create("Images/test_image_i8.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -463,7 +463,7 @@ local function TexturePVRAI88()
local img = cc.Sprite:create("Images/test_image_ai88.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -478,7 +478,7 @@ local function TexturePVR2BPPv3()
img:setPosition(cc.p(s.width/2.0, s.height/2.0))
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -494,7 +494,7 @@ local function TexturePVRII2BPPv3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -512,7 +512,7 @@ local function TexturePVR4BPPv3()
cclog("This test is not supported")
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -534,7 +534,7 @@ local function TexturePVRII4BPPv3()
else
cclog("This test is not supported")
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -551,7 +551,7 @@ local function TexturePVRRGBA8888v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -571,7 +571,7 @@ local function TexturePVRBGRA8888v3()
cclog("BGRA images are not supported")
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -587,7 +587,7 @@ local function TexturePVRRGBA5551v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -604,7 +604,7 @@ local function TexturePVRRGBA4444v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -621,7 +621,7 @@ local function TexturePVRRGB565v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -638,7 +638,7 @@ local function TexturePVRRGB888v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -655,7 +655,7 @@ local function TexturePVRA8v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -672,7 +672,7 @@ local function TexturePVRI8v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -689,7 +689,7 @@ local function TexturePVRAI88v3()
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -726,7 +726,7 @@ local function TexturePVRNonSquare()
local img = cc.Sprite:create("Images/grossini_128x256_mipmap.pvr")
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -745,7 +745,7 @@ local function TexturePVRNPOT4444()
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -764,7 +764,7 @@ local function TexturePVRNPOT8888()
img:setPosition(cc.p( s.width/2.0, s.height/2.0))
ret:addChild(img)
end
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -809,7 +809,7 @@ local function TextureAlias()
sprite2:runAction(scaleforever)
sprite:runAction(scaleToo)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -844,7 +844,7 @@ local function TexturePixelFormat()
ret:addChild(sprite1, 0)
-- remove texture from texture manager
cc.TextureCache:getInstance():removeTexture(sprite1:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite1:getTexture())
-- RGBA 4444 image (16-bit)
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A4444)
@ -853,7 +853,7 @@ local function TexturePixelFormat()
ret:addChild(sprite2, 0)
-- remove texture from texture manager
cc.TextureCache:getInstance():removeTexture(sprite2:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite2:getTexture())
-- RGB5A1 image (16-bit)
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB5_A1)
@ -862,7 +862,7 @@ local function TexturePixelFormat()
ret:addChild(sprite3, 0)
-- remove texture from texture manager
cc.TextureCache:getInstance():removeTexture(sprite3:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite3:getTexture())
-- RGB888 image
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RG_B888 )
@ -871,7 +871,7 @@ local function TexturePixelFormat()
ret:addChild(sprite4, 0)
-- remove texture from texture manager
cc.TextureCache:getInstance():removeTexture(sprite4:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite4:getTexture())
-- RGB565 image (16-bit)
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RG_B565)
@ -880,7 +880,7 @@ local function TexturePixelFormat()
ret:addChild(sprite5, 0)
-- remove texture from texture manager
cc.TextureCache:getInstance():removeTexture(sprite5:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite5:getTexture())
-- A8 image (8-bit)
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_A8 )
@ -889,7 +889,7 @@ local function TexturePixelFormat()
ret:addChild(sprite6, 0)
-- remove texture from texture manager
cc.TextureCache:getInstance():removeTexture(sprite6:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite6:getTexture())
local fadeout = cc.FadeOut:create(2)
local fadein = cc.FadeIn:create(2)
@ -908,7 +908,7 @@ local function TexturePixelFormat()
-- restore default
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_DEFAULT)
cc.TextureCache:getInstance():dumpCachedTextureInfo()
print(cc.Director:getInstance():getTextureCache():getCachedTextureInfo())
return ret
end
@ -997,16 +997,16 @@ local function TextureAsync()
for j=0, 7 do
local szSpriteName = string.format(
"Images/sprites_test/sprite-%d-%d.png", i, j)
cc.TextureCache:getInstance():addImageAsync(
cc.Director:getInstance():getTextureCache():addImageAsync(
szSpriteName, imageLoaded)
end
end
cc.TextureCache:getInstance():addImageAsync("Images/background1.jpg", imageLoaded)
cc.TextureCache:getInstance():addImageAsync("Images/background2.jpg", imageLoaded)
cc.TextureCache:getInstance():addImageAsync("Images/background.png", imageLoaded)
cc.TextureCache:getInstance():addImageAsync("Images/atlastest.png", imageLoaded)
cc.TextureCache:getInstance():addImageAsync("Images/grossini_dance_atlas.png",imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/background1.jpg", imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/background2.jpg", imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/background.png", imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/atlastest.png", imageLoaded)
cc.Director:getInstance():getTextureCache():addImageAsync("Images/grossini_dance_atlas.png",imageLoaded)
end
local schedulerEntry = nil
@ -1015,7 +1015,7 @@ local function TextureAsync()
schedulerEntry = scheduler:scheduleScriptFunc(loadImages, 1.0, false)
elseif event == "exit" then
scheduler:unscheduleScriptEntry(schedulerEntry)
cc.TextureCache:getInstance():removeAllTextures()
cc.Director:getInstance():getTextureCache():removeAllTextures()
end
end
@ -1048,7 +1048,7 @@ local function TextureGlClamp()
sprite:runAction(seq)
local function onNodeEvent(event)
if event == "exit" then
cc.TextureCache:getInstance():removeUnusedTextures()
cc.Director:getInstance():getTextureCache():removeUnusedTextures()
end
end
@ -1082,7 +1082,7 @@ local function TextureGlRepeat()
sprite:runAction(seq)
local function onNodeEvent(event)
if event == "exit" then
cc.TextureCache:getInstance():removeUnusedTextures()
cc.Director:getInstance():getTextureCache():removeUnusedTextures()
end
end
@ -1150,7 +1150,7 @@ local function TextureCache1()
sprite:setScale(2)
ret:addChild(sprite)
cc.TextureCache:getInstance():removeTexture(sprite:getTexture())
cc.Director:getInstance():getTextureCache():removeTexture(sprite:getTexture())
sprite = cc.Sprite:create("Images/grossinis_sister1.png")
sprite:setPosition(cc.p(s.width/5*2, s.height/2))
@ -1166,7 +1166,7 @@ local function TextureCache1()
sprite:setScale(2)
ret:addChild(sprite)
cc.TextureCache:getInstance():removeTextureForKey("Images/grossinis_sister2.png")
cc.Director:getInstance():getTextureCache():removeTextureForKey("Images/grossinis_sister2.png")
sprite = cc.Sprite:create("Images/grossinis_sister2.png")
sprite:setPosition(cc.p(s.width/5*4, s.height/2))
@ -1192,8 +1192,8 @@ local function TextureDrawAtPoint()
m_pTex2F:drawAtPoint(cc.p(s.width/2+50, s.height/2 - 50))
end
m_pTex1 = cc.TextureCache:getInstance():addImage("Images/grossinis_sister1.png")
m_pTex2F = cc.TextureCache:getInstance():addImage("Images/grossinis_sister2.png")
m_pTex1 = cc.Director:getInstance():getTextureCache():addImage("Images/grossinis_sister1.png")
m_pTex2F = cc.Director:getInstance():getTextureCache():addImage("Images/grossinis_sister2.png")
m_pTex1:retain()
m_pTex2F:retain()
@ -1226,8 +1226,8 @@ local function TextureDrawInRect()
m_pTex2F:drawInRect(rect2)
end
local m_pTex1 = cc.TextureCache:getInstance():addImage("Images/grossinis_sister1.png")
local m_pTex2F = cc.TextureCache:getInstance():addImage("Images/grossinis_sister2.png")
local m_pTex1 = cc.Director:getInstance():getTextureCache():addImage("Images/grossinis_sister1.png")
local m_pTex2F = cc.Director:getInstance():getTextureCache():addImage("Images/grossinis_sister2.png")
m_pTex1:retain()
m_pTex2F:retain()
@ -1260,7 +1260,7 @@ local function TextureMemoryAlloc()
cclog("updateImage"..tag)
m_pBackground:removeFromParent(true)
end
cc.TextureCache:getInstance():removeUnusedTextures()
cc.Director:getInstance():getTextureCache():removeUnusedTextures()
local file = ""
if tag == 0 then
@ -1364,7 +1364,7 @@ local function TexturePVRv3Premult()
-- PNG
cc.Texture2D:setDefaultAlphaPixelFormat(cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
cc.TextureCache:getInstance():removeTextureForKey("Images/grossinis_sister1-testalpha.png")
cc.Director:getInstance():getTextureCache():removeTextureForKey("Images/grossinis_sister1-testalpha.png")
local png = cc.Sprite:create("Images/grossinis_sister1-testalpha.png")
ret:addChild(png, 0)
png:setPosition(cc.p(size.width/4*3, size.height/2))

View File

@ -10,7 +10,7 @@ Paddle.__index = Paddle
local kPaddleStateGrabbed = 0
local kPaddleStateUngrabbed = 1
Paddle.m_state = kPaddleStateGrabbed
Paddle._state = kPaddleStateGrabbed
function Paddle:rect()
@ -26,37 +26,45 @@ function Paddle:containsTouchLocation(x,y)
return b
end
function Paddle:ccTouchBegan(x, y)
if (self.m_state ~= kPaddleStateUngrabbed) then
function Paddle:paddleWithTexture(aTexture)
local pPaddle = Paddle.new(aTexture)
pPaddle._state = kPaddleStateUngrabbed
pPaddle:registerScriptHandler(function(tag)
if "enter" == tag then
pPaddle:onEnter()
elseif "exit" == tag then
end
end)
return pPaddle
end
function Paddle:onEnter()
local listenner = cc.EventListenerTouchOneByOne:create()
listenner:setSwallowTouches(true)
listenner:registerScriptHandler(function(touch, event)
print(string.format("Paddle::onTouchBegan id = %d, x = %f, y = %f", touch:getId(), touch:getLocation().x, touch:getLocation().y))
if (self._state ~= kPaddleStateUngrabbed) then
return false
end
self.m_state = kPaddleStateGrabbed;
return true;
end
function Paddle:ccTouchMoved(x, y)
self:setPosition( cc.p(x,y) );
end
function Paddle:ccTouchEnded(x, y)
self.m_state = kPaddleStateUngrabbed;
end
function Paddle:onTouch(eventType, x, y)
if eventType == "began" then
return self:ccTouchBegan(x,y)
elseif eventType == "moved" then
return self:ccTouchMoved(x,y)
elseif eventType == "ended" then
return self:ccTouchEnded(x, y)
if not self:containsTouchLocation(touch:getLocation().x,touch:getLocation().y) then
return false
end
self._state = kPaddleStateGrabbed
return true
end,cc.Handler.EVENT_TOUCH_BEGAN )
listenner:registerScriptHandler(function(touch, event)
print(string.format("Paddle::onTouchMoved id = %d, x = %f, y = %f", touch:getId(), touch:getLocation().x, touch:getLocation().y))
assert(self._state == kPaddleStateGrabbed, "Paddle - Unexpected state!")
local touchPoint = touch:getLocation()
local curPosX,curPosY = self:getPosition()
self:setPosition(cc.p(touchPoint.x,curPosY))
end,cc.Handler.EVENT_TOUCH_MOVED )
listenner:registerScriptHandler(function(touch, event)
assert(self._state == kPaddleStateGrabbed, "Paddle - Unexpected state!")
self._state = kPaddleStateUngrabbed
end,cc.Handler.EVENT_TOUCH_ENDED )
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listenner, self)
end
function Paddle:paddleWithTexture(aTexture)
local pPaddle = Paddle.new(aTexture);
self.m_state = kPaddleStateUngrabbed;
return pPaddle;
end

View File

@ -48,22 +48,11 @@ local function doStep(delta)
m_ball:draw();
end
local function onTouch(event, x, y)
for _,paddle in ipairs(m_paddles) do
if paddle:containsTouchLocation(x,y) == true then
return paddle:onTouch(event, x, y)
end
end
return true
end
local function CreateTouchesLayer()
layer = cc.Layer:create()
m_ballStartingVelocity = cc.p(20.0, -100.0);
local mgr = cc.TextureCache:getInstance()
local mgr = cc.Director:getInstance():getTextureCache()
local texture = mgr:addImage(s_Ball)
m_ball = Ball.ballWithTexture(texture);
@ -72,7 +61,7 @@ local function CreateTouchesLayer()
layer:addChild( m_ball );
m_ball:retain();
local paddleTexture = cc.TextureCache:getInstance():addImage(s_Paddle);
local paddleTexture = cc.Director:getInstance():getTextureCache():addImage(s_Paddle);
local paddlesM = {}
@ -106,9 +95,6 @@ local function CreateTouchesLayer()
-- schedule
layer:scheduleUpdateWithPriorityLua(doStep, 0)
layer:setTouchEnabled(true)
layer:registerScriptTouchHandler(onTouch)
return layer
end

View File

@ -50,6 +50,7 @@ static AppDelegate s_sharedApplication;
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
[__glView setMultipleTouchEnabled:YES];
// Use RootViewController manage CCEAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];