Aligning scene nodes while ui sceneView is animately resized
-
Hey everyone,
awkward title of the topic, I know. I struggled with fitting nodes in resizing sceneViews. I have a sceneView, which is resized via animation by pushing a button. The question was how to stick the scene at the top of the view. I have found a solution, but because of the fact I am new to that stuff Iβd like to post the code here with the silent question if there is a better way or if it is a common way.
from scene import * import ui class MyScene(Scene): def __init__(self): Scene.__init__(self) self.background_color= '#eee' self.frm = ShapeNode(parent=self, fill_color='red', stroke_color='clear') def setup(self): self.viewSizeHasChanged() def viewSizeHasChanged(self): self.frm.position = (150,self.view.height/2-(500-self.view.height)/2) self.frm.path = ui.Path.rect(0,0,250,450) class GUI(ui.View): def __init__(self): self.background_color = '#ddd' self.scales = (100, 500) self.state = True self.separator_H = 10 self.mainView = ui.View(frame=(50,50,300,500), background_color='#fff') self.add_subview(self.mainView) self.sn = SceneView() self.sn.frame = self.mainView.bounds self.mainView.add_subview(self.sn) self.sn.scene = MyScene() self.btn_Do = ui.Button(name='Do', title='Do', background_color= '#ddd', corner_radius = 12, action = self.btn_tapped) self.btn_Do.frame = (175, 275, 50, 50) self.add_subview(self.btn_Do) def btn_tapped(self, sender): if sender.name == 'Do': self.state = (self.state+1)%2 self.sn.scene.viewSizeHasChanged() self.animate(self.scales[self.state]) def animate(self, H): def animation(): self.mainView.frame = (50,(600-H)/2,300,H) ui.animate(animation, duration=1.0) if __name__ == '__main__': GUI().present('fullscreen')
Thx for every hint guys
rownn
-
@JonB said:
When you look at the code for scene, there is an _update method that is getting called, that handles the Actions. Then it calla update. So performance wise, I think Actions and update methods are similar.
exactly. in my games ill actually use this to my advantage by staging animations and checks. for example you can move a node with
Action.move_by
and have a check inupdate
to make sure node isnt outside the screen. this insures the move is done before the check. Alternativily you can move your check intoScene.did_evaluate_actions()
only reason i dont use this method is because your check must wait until the action is finished and that could have been too long depending on current check being used.heres an example if anyone wants using all three steps to move the node and rmove it if off screen.
def did_evaluate_actions(self): self.move_node() def move_node(self): self.run_action(Action.move_by(-100, 0, 1.0, TIMING_EASE_IN_OUT)) def update(self): if self.position[0] < -self.size[0]-10: self.run_action(Action.remove())
adding a light rotate at the end and begining would give the rocking of a stop and go effect like in a cartoon. βΊοΈ
-
Hey guys,
amazing again. I think I will study you snippets over a glass of wine this evening :)
-
@rownn said:
Hey guys,
amazing again. I think I will study you snippets over a glass of wine this evening :)
π»
-
last edited by
-
@cvp said:
@mikael said:
self.open = self.open == False
I prefer ππ
self.open = not self.open
i agree.. it still drives me nuts that i cant use..
boolean = !boolean
catch myself still doing it after about a year of python lol
-
For this part of the discussion alone this thread is worthy to exist. :)
@rownn said: (boolean+1)%2
The school math way@mikael said: boolean = boolean == False
The developers way@cvp said: boolean = not boolean
The pythonish way@stephen said: boolean = !boolean
The beautiful but !pythonish way
-
Pythonic not Pythonish. ;-) 500+ pages of results!
-
@rownn In my very old Fortan past, I used an integer 1 or 0, thus
flag = 1 - flag
-
@cvp, I vote for your version, which I plain forgot.