本文整理汇总了Python中cocos.cocosnode.CocosNode.do方法的典型用法代码示例。如果您正苦于以下问题:Python CocosNode.do方法的具体用法?Python CocosNode.do怎么用?Python CocosNode.do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocos.cocosnode.CocosNode
的用法示例。
在下文中一共展示了CocosNode.do方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_crossing_max_at_1st_step
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_update_crossing_max_at_1st_step(self, duration1, duration2):
# next_elapsed > max(duration1, duration2)
global rec
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.spawn(a1, a2)
rec = []
node.do(composite)
elapsed = 0.0
next_elapsed = max(duration1, duration2)*1.1 # above max
dt = next_elapsed - elapsed
node._step(dt)
recx = [ e for e in rec if e[1]!='step' ]
rec = [ e for e in recx if e[0]==name1]
print 'rec',rec
assert rec[0][1]=='start'
assert rec[1][1]=='update' and rec[1][2]==1.0
assert rec[2][1]=='stop'
assert len(rec)==3
rec = [ e for e in recx if e[0]==name2]
print 'rec:', rec
assert rec[0][1]=='start'
assert rec[1][1]=='update' and rec[1][2]==1.0
assert rec[2][1]=='stop'
assert len(rec)==3
示例2: test_update_crossing_total_duration_at_1st_step
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_update_crossing_total_duration_at_1st_step(self, duration1, duration2):
# elapsed==0, next_elapsed>=duration1 + duration2
global rec
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
elapsed = 0.0
rec = []
composite = ac.sequence(a1, a2)
node.do(composite)
next_elapsed = duration1 + duration2 +fe
dt = next_elapsed - elapsed
node._step(dt)
# expected: for both actions start-update(1)-stop called, in that order
recx = [ e for e in rec if e[1]!='step' ]
rec = [ e for e in recx if e[0]==name1]
print 'rec',rec
assert len(rec)==3
assert rec[0][1]=='start'
assert rec[1][1]=='update' and rec[1][2]==1.0
assert rec[2][1]=='stop'
rec = [ e for e in recx if e[0]==name2]
print 'rec',rec
assert len(rec)==3
assert rec[0][1]=='start'
assert rec[1][1]=='update' and rec[1][2]==1.0
assert rec[2][1]=='stop'
示例3: test_updating_above_duration1_below_duration
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_updating_above_duration1_below_duration(self, duration1, duration2):
global rec
if duration2==0.0:
return
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.sequence(a1, a2)
node.do(composite)
elapsed = 0.0
next_elapsed = (duration1 + duration2)/2.0
dt = next_elapsed - elapsed
node._step(dt)
elapsed = next_elapsed
next_elapsed = (next_elapsed + composite.duration)/2.0
dt = next_elapsed - elapsed
rec = []
node._step(dt)
assert len([e for e in rec if e[0]==name1])==0
rec = [ e for e in rec if e[1]!='step' ]
print rec
assert rec[0][1]=='update'
assert abs(rec[0][2]-(next_elapsed-duration1)/duration2)<fe
assert len(rec)==1
示例4: test_update_crossing_duration1_not_duration_at_1st_step
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_update_crossing_duration1_not_duration_at_1st_step(self, duration1, duration2):
global rec
if duration2==0.0:
return
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.sequence(a1, a2)
rec = []
node.do(composite)
elapsed = 0.0
next_elapsed = (duration1 + duration2)/2.0
dt = next_elapsed - elapsed
node._step(dt)
#expect start, update(1), stop for action 1, start + update(x) for action2
recx = [ e for e in rec if e[1]!='step' ]
rec = [ e for e in recx if e[0]==name1]
print 'rec',rec
assert rec[0][1]=='start'
assert rec[1][1]=='update' and rec[1][2]==1.0
assert rec[2][1]=='stop'
assert len(rec)==3
rec = [ e for e in recx if e[0]==name2]
print 'rec',rec
assert rec[0][1]=='start'
assert rec[1][1]=='update'
assert abs(rec[1][2]-(next_elapsed-duration1)/duration2)<fe
assert len(rec)==2
示例5: test_update_crossing_min_not_max_not_at_1st_step
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_update_crossing_min_not_max_not_at_1st_step(self, duration1, duration2):
# 0< min< next_elapsed < max
global rec
# only applies if min(duration1, duration2)>=epsilon >0.0 , 1.0/epsilon
# well defined
try:
need_test = (duration1!=duration2)
a = 1.0/duration1
b = 1.0/duration2
except ZeroDivisionError:
need_test = False
if not need_test:
# the test dont make sense for the parameters received, skip
return
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.spawn(a1, a2)
node.do(composite)
elapsed = 0.0
dt = min(duration1, duration2)/2.0
node._step(dt)
elapsed += dt # below min
# between duration1 and duration2
next_elapsed = (duration1 + duration2)/2.0
dt = next_elapsed - elapsed
rec = []
node._step(dt)
rec = [ e for e in rec if e[1]!='step' ]
# expected:
# the action with min duration will only call .update(1.0) and
# .stop(), in that order
# the action with max duraction will only call .update with apropiate t
if duration1 < duration2:
oname1 = name1
oduration1 = duration1
oname2 = name2
oduration2 = duration2
else:
oname1 = name2
oduration1 = duration2
oname2 = name1
oduration2 = duration1
orec1 = [ e for e in rec if e[0]==oname1 ]
assert orec1[0]==(oname1, 'update', 1.0)
assert orec1[1]==(oname1, 'stop')
assert len(orec1)==2
orec2 = [ e for e in rec if e[0]==oname2 ]
assert len(orec2)==1
assert orec2[0][1]=='update'
assert abs(orec2[0][2] - next_elapsed/oduration2)<fe
示例6: test_Loop_InstantAction
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_Loop_InstantAction():
rec = []
def f(x):
rec.append(x)
node = CocosNode()
template_action = cocos.actions.instant_actions.CallFunc(f, 1)
n = 5
action = template_action * n
node.do(action)
assert rec == [1] * n
示例7: test_start
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_start(self, duration1, duration2):
global rec
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.spawn(a1, a2)
rec = []
node.do(composite)
assert [e for e in rec if e[0]==name1][0]==(name1, 'start')
assert [e for e in rec if e[0]==name2][0]==(name2, 'start')
示例8: test_update_crossing_min_not_max_at_1st_step
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_update_crossing_min_not_max_at_1st_step(self, duration1, duration2):
# min< next_elapsed < max
global rec
# expect start, [xxx,]update(1), stop for shortest action
# only applies if min<max
need_test = (duration1 < duration2)
if not need_test:
return
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.spawn(a1, a2)
rec = []
node.do(composite)
elapsed = 0.0
# between duration1 and duration2
next_elapsed = (duration1 + duration2)/2.0
dt = next_elapsed - elapsed
node._step(dt)
print 'rec:', rec
rec = [ e for e in rec if e[1]!='step' ]
if duration1 < duration2:
oname1 = name1
oduration1 = duration1
oname2 = name2
oduration2 = duration2
else:
oname1 = name2
oduration1 = duration2
oname2 = name1
oduration2 = duration1
orec1 = [ e for e in rec if e[0]==oname1 ]
print orec1
assert orec1[0]==(oname1, 'start')
assert orec1[1]==(oname1, 'update', 1.0)
assert orec1[2]==(oname1, 'stop')
assert len(orec1)==3
orec2 = [ e for e in rec if e[0]==oname2 ]
print orec2
assert len(orec2)==2
assert orec2[0]==(oname2, 'start')
assert orec2[1][1]=='update'
assert abs(orec2[1][2] - next_elapsed/oduration2)<fe
示例9: test_update_1_called
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_update_1_called(self):
global rec
duration = 2.0
original_action = UIntervalAction('original', duration)
modified_action = ac.AccelDeccel(original_action)
node = CocosNode()
node.do(modified_action)
dt = duration * 1.0
rec = []
node._step(dt)
print 'rec:', rec
update_record = rec[-1]
assert update_record[1] == 'update'
assert update_record[2] == 1.0
示例10: test_start
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_start(self):
global rec, next_done
next_done=0
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UAction(name1)
a2 = UAction(name2)
composite = ac.spawn(a1, a2)
rec = []
node.do(composite)
print 'start rec:', rec
assert rec[0]==(name1, 'start')
assert rec[0]==(name1, 'start')
assert len(rec)==2
示例11: test_step_setting_done1_done2
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_step_setting_done1_done2(self):
global rec, next_done
next_done=0
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UAction(name1)
a2 = UAction(name2)
composite = ac.spawn(a1, a2)
a_copy = node.do(composite)
dt = 0.1
rec = []
next_done = 3
node._step(dt)
print rec
recx = [e for e in rec if e[0]==name1]
assert recx[0][1]== 'step'
assert recx[1][1]=='stop'
assert len(recx)==2
recx = [e for e in rec if e[0]==name2]
assert recx[0][1]=='step'
assert recx[1][1]=='stop'
assert len(recx)==2
assert a_copy.done()
rec = []
node._step(dt)
assert len(rec)==0
assert len(node.actions)==0
示例12: test_remove_action
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_remove_action(self):
global rec, next_done
next_done = 0
node = CocosNode()
name1 = '1'
action1 = UAction(name1)
name2 = '2'
action2 = UAction(name2)
a1_copy = node.do(action1)
a2_copy = node.do(action2)
assert len(node.actions)==2
rec = []
node.remove_action(a1_copy)
recx = [ e for e in rec if e[0]==name1]
assert recx[0]==(name1, 'stop')
assert len(recx)==1
rec =[]
dt = 0.1
node._step(dt)# needed to complete delete, will traceback if remove failed
assert len(node.actions)==1
assert a2_copy in node.actions
recx = [ e for e in rec if e[0]==name1]
assert len(recx)==0
示例13: test_updating_above_min_below_max
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_updating_above_min_below_max(self, duration1, duration2):
# min < elapsed < next_elapsed < max
global rec
need_test = (duration1!=duration2)
if not need_test:
return
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.spawn(a1, a2)
node.do(composite)
elapsed = 0.0
next_elapsed = (duration1 + duration2)/2.0 # above min, below max
dt = next_elapsed - elapsed
node._step(dt)
elapsed = next_elapsed
next_elapsed = (elapsed + max(duration1, duration2))/2.0
dt = next_elapsed - elapsed
rec = []
node._step(dt)
# expected:
# no call from the action with min duration
# only one call from the action with max duration and will be .update
if duration1 < duration2:
oname1 = name1
oname2 = name2
else:
oname1 = name2
oname2 = name1
rec_lo = [ e for e in rec if e[0]==oname1]
print 'rec_lo:', rec_lo
assert len(rec_lo)==0
rec = [ e for e in rec if e[0]==oname2]
rec = [ e for e in rec if e[1]!='step' ]
print 'rec hi:',rec
assert len(rec)==1
assert (rec[0][1]=='update' and
abs(rec[0][2] - next_elapsed/max(duration1, duration2))<fe)
示例14: test_target_set
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_target_set(self):
global rec, next_done
node = CocosNode()
name1 = '1'
a1 = UAction(name1)
composite = ac.Repeat(a1)
rec = []
a_copy = node.do(composite)
assert a_copy.action.target==node
示例15: test_updating_below_min
# 需要导入模块: from cocos.cocosnode import CocosNode [as 别名]
# 或者: from cocos.cocosnode.CocosNode import do [as 别名]
def test_updating_below_min(self, duration1, duration2):
# next_elapsed < min(duration1, duration2)
global rec
# only applies if min(duration1, duration2)>=epsilon >0.0 , 1.0/epsilon
# well defined
need_test = True
try:
a = 1.0/duration1
b = 1.0/duration2
except ZeroDivisionError:
need_test = False
if not need_test:
# the test dont make sense for the parameters received, skip
return
node = CocosNode()
name1 = '1'
name2 = '2'
a1 = UIntervalAction(name1, duration1)
a2 = UIntervalAction(name2, duration2)
composite = ac.spawn(a1, a2)
node.do(composite)
elapsed = 0.0
min_duration = min(duration1, duration2)
for next_elapsed in [ min_duration/3.0, min_duration/2.0]:
dt = next_elapsed - elapsed
rec = []
node._step(dt)
rec = [ e for e in rec if e[1]!='step' ]
rec1 = [ e for e in rec if e[0]==name1]
assert len(rec1)==1
assert (rec1[0][1]=='update' and
abs(rec1[0][2]-next_elapsed/duration1)<fe
)
rec2 = [ e for e in rec if e[0]==name2]
assert len(rec2)==1
assert(rec2[0][1]=='update' and
abs(rec2[0][2]-next_elapsed/duration2)<fe
)
elapsed = next_elapsed