Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello β I'm @olemoritz on Twitter.
Flappy bird
-
w()
-update(self)
-self.dt
-self
-self.size.w
-lw()This yes, here it looks quite easy.
I'm trying to write for now like I can, though it's not the best way and I get annoying bugs sometimes
What it means that it all was linear?the full script ill feel like a spider web lol but ill annotate as much as i can.
Wow I'm scared
-
@stephen You said @in_background makes smth run on a dif thread. I'm not into the ui for now, but what is the dif thread?
-
@Karina what i mean by linear is the scripts are writen in a step by step manner. and then the rest is all focused inside the loop body. just a way i refer to simple writing techniques. where alternatively i tend write in a manner that jumps around. multiple inheritence, conroller types, delegates.. and so on.
@karina said:
@stephen You said @in_background makes smth run on a dif thread. I'm not into the ui for now, but what is the dif thread?
ui.in_background()
decorator executes the following process in the main thread instead of on your current event loop's. whenever you call module levelrun()
function fromscene
or class methodView.Present()
fromui
you create a new event loop separate from Interpreters main thread. Python uses GIL (Global Interpreter Lock) that only alows one thread. you can still use multiprocessing though. for info on that check out Asynchronous programming. the reason for GIL is objC memory managment is not considered "Thread Safe".Docs said:
ui.in_background(fn):
Call a function on the main interpreter thread. This is useful to perform long-running tasks from an action or delegate callback without blocking the UI. It can also be used for functions that donβt support being called from the main UI thread (e.g. console.alert()).
as far as you not using the
ui
module... you have been this whole time.. lolscene
usesui
quite heavely. and you dont need to importui
separatly. by usingfrom scene import *
ui
is also included. from your game just callui.
and then whatever you want from there. when you run yourscene
game it actually prepares theui
stuff for you and then presents aSceneView
if you setup a customView
class in your game script you can create ascene.SceneView
and set itsSceneView.scene
property to your Game Object. then instead of usingrun(MyScene())
you present the View which places your game in its own frame on your screen making it easy to add ui objects as your gui for ur game. -
@Karina and im almost finished with the Animation/Actions demo. should be posted later this evening.
currently 5pm my time
-
@Karina and im almost finished with the Animation/Actions demo. should be posted later this evening.
currently 5pm my timeπ
-
def touch_began(self, touch): sound.play_effect('arcade:Jump_4') self.player.texture = player_textures[3] jumping = [A.move_by(0, 100, 0.2), A.wait(1), A.move_by(0, -100, 0.1)] self.player.run_action(A.sequence(jumping)
I tried to make him jump but it doesn't work. I know there should be a more clever way to do that but I have no idea
-
@Karina I havenβt used Actions much, I prefer animating nodes myself. But theoretically, from reading the docs, your code should work (assuming your indentation is correct and your actual code doesnβt miss the closed bracket at the end)
-
@stephen you mean fixing the Node pos by yourself? Action should work smoother and easier to write. If it also worked here)
And why in your program you called this blocks brushes?π -
I began to read about threads and sometimes don't understand what about this all, but in general understand. And for what here to use them? It encreases the speed of smth?
-
@Karina @Drizzel here is a demo for action timing. i intended to have much more informative and visually attractive version and ill improve it in time but for noe you can see a visual difference between each interpolation.
note: this is formated for ipad only. future versions will have formatting for other devices. i appoligise.
from scene import * class BaseSign(SpriteNode): def __init__(self, texture=None, tag='Sign', *args, **kwargs): super().__init__(texture=texture, *args, **kwargs) self.anchor_point=(0.0, 1.0) self.position = Point(10, get_screen_size()[1]-10) self.z_position=1 self.color='#000000' self.size=Size(get_screen_size()[0]-20, get_screen_size()[1]-20) self.bg=SpriteNode( texture=None, color='#80cdff', position=Point(3, -3), anchor_point=(0.0, 1.0), size=Size(get_screen_size()[0]-26, get_screen_size()[1]-26), parent=self) self.sign=LabelNode( '', position=Point(1, 15), z_position=3, font=('Ubuntu Mono', 18), parent=self.bg, color='#000000', anchor_point=(0.0, 1.0)) class MyScene (Scene): def setup(self): self.dur=5 self.moveToPos=(73, 245) self.sign=BaseSign(parent=self, position=self.size/2) self.sign.sign.text=self.Text() for x in range(16): b=SpriteNode(Texture('pzl:BallGray'), size=Size(16, 16), color='#00f90b', position=Point(73, (get_screen_size()[1]-132) - 36.15*x), z_position=9, parent=self) b.run_action( Action.repeat( Action.sequence( Action.call(self.UpdateTime, 0.1), Action.wait(0.5), Action.move_to(self.moveToPos[1], b.position[1], 2, x), Action.move_to(self.moveToPos[0], b.position[1], 2, x)),-1)) def UpdateTime(self, node, progress): if self.speed is 1: self.speed=0.5 else: self.speed=1 self.sign.sign.text=self.Text() def Text(self): return f''' ββββββββββββββββββββββββββ β BUILT_IN_CONSTANT β β βββββ¦βββββββββ¦βββββββββββ£ β 2s β 2 part β 1x speed β β βββββ©βββββββββ©βββββββββββ£ βTIMING_LINEAR β βββ‘ βββ’ βTIMING_EASE_IN_2 β βββ‘ βββ’ βTIMING_EASE_IN_2 β βββ‘ βββ’ βTIMING_EASE_OUT β βββ‘ βββ’ βTIMING_EASE_OUT_2 β βββ‘ βββ’ βTIMING_EASE_IN_OUT β βββ‘ βββ’ βTIMING_SINODIAL β βββ‘ βββ’ βTIMING_ELASTIC_OUT β βββ‘ βββ’ βTIMING_ELASTIC_IN β βββ‘ βββ’ βTIMING_ELASTIC_IN_OUT β βββ‘ βββ’ βTIMING_BOUNCE_OUT β βββ‘ βββ’ βTIMING_BOUNCE_IN β βββ‘ βββ’ βTIMING_BOUNCE_IN_OUT β βββ‘ βββ’ βTIMING_EASE_BACK_IN β βββ‘ βββ’ βTIMING_EASE_BACK_OUT β βββ‘ βββ’ βTIMING_EASE_BACK_IN_OUT β βββ‘ βββ’ ββββββββββββββββββββββββββ''' if __name__ == '__main__': run(MyScene(), show_fps=True)
-
@Karina I think you got me mixed up with @stephen :) And yes, I do prefer to fix the nodeβs position manually.
My version of flappy bird I posted here some days ago is a good example. I used basic physics formulas to give the bird an acceleration, and then use that to calculate the birdβs speed and thus position at a given time. Then adjusting the gravity and weight parameters made the motion feel βjust rightβ (in my opinion).
Technical stuff aside, I just do it for greater control, so I can get the feeling of motions right.
-
@stephen looking good! I always was a little too lazy to try them all out... and Iβm not using scene much nowadays.
-
@Karina said:
@stephen you mean fixing the Node pos by yourself? Action should work smoother and easier to write. If it also worked here)
And why in your program you called this blocks brushes?πi did mean changing the nodes pos manually and its prety smooth esspecially when you implement your own interpolation (the TIMING constants used with Actions).
what my main concern was that you were creating an Action Proccess for every block instead of having one Action Process for a group of blocks. this group would be the brushes i keep talking about.
in my older exampe i did refer to blocks as brushes and then later i corrected myself. in my final example (the game not the action demo and i havnt finished my version of the game yet) will have "brushes" and everything will be anotated so you its easy to understand each part.
Brush: predefined graphical structure to be instantiated multiple times. often cached for fast referencing." Example: Trees and Vilages in MineCraft..
-
@Karina said:
I began to read about threads and sometimes don't understand what about this all, but in general understand. And for what here to use them? It encreases the speed of smth?
I certainly donβt know everything about threads either, but hereβs my understanding of them.
The basics:
-
I think of threads like... well threads, as in strings or a thin rope. And when you open a thread, the code in this thread is run separated to other threads.
-
Thus Threads allow for separate codes to run βat the same timeβ (this technically isnβt possible, and is done through some tricks so that it appears so. Thus the quotation mark. But Iβm not here to confuse you, so letβs go on)
-
Therefore you can have one section of code that (for example) has a time.sleep(100000) in it, and a thread that prints stuff in an infinite loop. Since they run in different threads, your code will still print stuff, even though thereβs a stupidly long sleep statement in it
Edit If you want some coding examples, I can write you some with comments
-
-
###Quick Update..
Nearly finished with the example game. I usually dont take this long but lifes been crazy lol
Done:
- EventManager
- block type classes
- GameObject class for creating individual objects
- Brush class for creating brush objects (template groups of GameObjects)
- land and sky generation
- Obsticle Gap Generation (better flow of gap hieght generation)
- Animation Class (added to GameObjects and Brushes as Instance Properties)
- Standard Obsticle Brush (objects with gap to flap/fly through)
- Connection of GameObjects, Brush Objects, Animations, EventManager and Scene Class. (pretymuch everyone can talk to everyone and all get Tick/Update calls to stay current)
TODO:
- Player class
- points score and rewards system
- Main Menu
- Settings Menu (maybe.. depends on time)
- PowerUps/Buffs/Boosters
- Game State Handle
NOTE:
@Karina did the Action timing demo help you understand the differences between each? it wasnt as informative as i like but figured it was ok givin the visual aspect
-
@Drizzel But in pythonista threads can't run in parallel, so it shouldn't increase the speed. So what benefits we have?
And when I put sleep, I don't want things to print###Quick Update..
Already some familiar things in it)
-
@Karina did the Action timing demo help you understand the differences between each? it wasnt as informative as i like but figured it was ok givin the visual aspect
@stephen Yes but it seems that all they are alike, some are nearly the same. But what the columns 2s, 2 part, 1x speed?
And how did you built this table?)And I'm learning, most of time with my ipad, the most important that it's suitable for it
-
@Karina Now yes, threads may not always speed up your program. But they can keep your program responsive even though thereβs some time consuming task being done. I also sometimes use them to constantly check if a variable changed, and then trigger a function. (Thereβs better ways to do that. But hey, Iβm learning too.)
Even though this is in no way specific to Pythonista, letβs take a slight detour. Some time ago, I built a door manager for the chicken pen of my family (yeah, itβs a bit unusual). It opens and closes the door at given times, but also constantly checks a button and email for a manual overrides. Since the button needs to be checked every 0.1 seconds, but checking the email takes about 4 seconds (establishing a connection to the google servers takes some time), the button wouldnβt be checked while the code is trying to get the new email. This is solved with threads, so they get checked in parallel, not after each
Therefore the button stays responsive, even though checking mails uses up a lot of time -
@Drizzel Sorry, i've not so understood what have you done. What means door manager for chicken pen? Your family has a chicken that has a pen and needs door manager??) what
But what here does the thread I got -
@Karina Yeah, we have a little βchicken houseβ and I wrote a script that opens and closes the door by turning on and off a motor. But thatβs not the point :) I just needed an example to better illustrate the uses of threads