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.
[SPACE ESCAPE]-Game example to help with Game dev
-
@stephen I agree. I have also programmed in very big projects of several man-years code and we were all very good in our programming language, and we had to follow some rules to be sure all our modules were coherent and understandable by others.
When I said that, I mean for my little own projects with only one user, like my wife, a friend or me. -
ohhhh lol ok ya i used to have projects with my brother inlaw and i used to hide stuff in the code and he would find them as bugs and get real excited but then i stopped and he would just find my horrible code and get upset ππ
-
@JonB @mikael @ccc and anyone else that might be able to explain lol
I decided to setup some checks and value sets to format sizes and scales so that the game will run on iphone and i get a very odd syntax error on line
702
but this only appears when i run it on the phone... Any idea what is causing this? or does this not even happen for you?
the error gives no info other than annotating the line -
@stephen same iOS, Pythonista, Python 2or3?
-
@stephen, runs on my iPhone, no syntax error.
-
-
-
@Karina just play with it. i separated everything the way i did so you can change somthing then play it to see how your changes had effect. the best way to learn is to have fun with it. and if you break it past return lol just start over. i can answer any questions and at some point you can add to it. making new brushes and adding new levels ππππ€
-
@Karina please dont hesitate with any questions. and if it will help i can break the code into hunks according to where you might be stuck on
-
-
@Karina No Problem. its tough at first. just hang in there and it will be second nature before you know it
-
@stephen yes, not long ago oop was to me like π€―
-
@Karina said:
@stephen yes, not long ago oop was to me like π€―
i started roughly 6 years ago. first with C# then C++ then a mixture of java/html/css and now python lol until python it was all video game related. i started pyton because at the time i phly had an iPhone and i needed to write a program that generated WorkOrders for Excel that the place i was working and ive now made it my gol/mission to makevan RPG with decent quality and functionality expected from all platforms. mainly because of all the reviews saying Python was horible for creating games at the magnitude ive set my goal to. so far it has been wonderfull. my first project i ever finished was an inventory system writen in C# with MonoBehavior API on Unity3D. was a π€― crash course.. but still fun lol
-
@stephen so you've mainly focused on games?
Unity 3D is for 3D games as I think. Quite a difficult thing for beginning
And pythonista just for fun? -
I tried to download postgresql in theese days and all the time problems...
And pythonista when I don't have pc with me -
@katrina Pythonista and python at first was for my Work Order project. mainly because i needed mobility. After that project was finished i guess it became an educational mission to add Python to my Resume π i have alwys done Game Dev because i find its the best way to learn a new Language. at least for myself. how is your game coming along?
-
@stephen I began to read ui cause in many games need it. It seems more difficult than scene, maybe because there's no tutorial like in scene
I want to build four buttons up, down, right, left and when you tap it, it prints down, left and so on. I'm between your alien, mine and this, helps to change what I'm doing -
@Karina yes it does help alot.
ui
is not too bad it does have more components such as:- Button
- SegmentControl
- TableView
- WebView
- NavigationView
- ScrollView
- Slider
- Switch (Radeo buttons)
- Label
- TextView
- DatePicker
- ListDataSource
- Image
- ImageView
- View
plus a few more but those seem to be the main ones.
where for
scene
you have:- SpriteNode
- LabelNode
- Texture
- Scene
- EffectNode
- SceneView
scene
is an extension ofui
and theNode
subclasses areView
subclasses just enhanced for a VideoGame Environment.i worded that last bit weird but im not sure how to write it lol sorry..
For example:
ui.Image
βsceneTexture
loads the Image into the GPU PipeLine
ui.ImageView
βscene.SpriteNode
Provides OpenGL functionality for custom shaders-
ui.Label
βscene.LabelNode
Simple text to screen but you get more control of visual components
As for the rest you can still achieve, just takes more work to build from scratch. So to make a button in
scene
you could do the following for example:import scene class EventHandler: children=[] event_loop=None @classmethod def add_child(cls, node): cls.children.append(node) if cls.event_loop == None: cls.event_loop = node.scene @classmethod def touch_began(cls, touch): for child in cls.children: if cls.event_loop.point_from_scene(touch.location) in child.frame: child.Button_Tapped() class ButtonNode(scene.SpriteNode): def __init__( self, name='ButtonNode', bgTexture='card:BackBlue1', tint='white', border='pzl:Button1', text_color='white', borderColor='#000d98', accessoryColor='red', icon='plf:Tile_BoxItem', accessory='emj:Exclamation_Mark_2', anchor_point=(0.5, 0.5), font_family='Helvetica', font_size=16, parent=None, x=0, y=0, w=64, h=64, action=None, text='', enabled=True, *args, **kwargs): self.texture=self._init_textures(border) self.icon=self._init_textures(icon) self.accessory=self._init_textures(accessory) self.border=self._init_textures(bgTexture) self.name=name self.enabled=enabled self.text=text self.font_family=font_family self.color=tint self.text_color=text_color self.borderColor=borderColor self.showAccesory=False self.accessoryColor=accessoryColor self.components=dict({ 'border':None, 'accessory':None, 'icon':None, 'label':None}) self.font_size=font_size self.parentNode=parent self.x, self.y, self.w, self.h=x, y, w, h self.rect=scene.Rect(x, y, w, h) self.position=scene.Point(x, y) self.size=scene.Size(w/100*80, h/100*80) self.button_action=action self.anchor_point=anchor_point super().__init__(texture=self.texture, parent=parent, *args, **kwargs) self._setup(self.border, self.icon, self.accessory, self.components) def _init_textures(self, img): if type(img) == str or type(img) == scene.ui.Image: return scene.Texture(img) else: return None def _setup(self, b, i, a, c): EventHandler.add_child(self) if b != None: c['border']=scene.SpriteNode( texture=b, size=self.size/100*95, parent=self, z_position=0, color=self.borderColor) if a != None: c['accessory']=scene.SpriteNode( texture=a, size=self.size/5, position=scene.Point(-self.size[0]/2+20, self.size[1]/2-15), parent=self, z_position=4, color=self.accessoryColor) if i != None: c['icon']=scene.SpriteNode( texture=i, size=scene.Size(self.size[1]/3, self.size[1]/3), position=scene.Point(self.w - self.size[1]/4 , 0), parent=self, z_position=9) if self.text: c['label']=scene.LabelNode( text=self.text, font=(self.font_family, self.font_size), position=scene.Point(-self.w/4 , 0), anchor_point=(0.5, 0.5), color=self.text_color, parent=self, z_position=10) def Button_Tapped(self): if self.components['accessory'].alpha > 0: self.components['accessory'].alpha = 0 if self.enabled: self.button_action(self) #--------------------------------------------------------------------------- def my_button_action(sender): print(sender.text) class main(scene.Scene): def setup(self): self.my_button_up=ButtonNode( text='up', parent=self, position=scene.Point(self.size[0]/2, self.size[1]/2+100), size=scene.Size(150, 75), action=my_button_action) self.my_button_right=ButtonNode( text='right', parent=self, position=scene.Point(self.size[0]/2+100, self.size[1]/2), size=scene.Size(150, 75), action=my_button_action) self.my_button_down=ButtonNode( text='down', parent=self, position=scene.Point(self.size[0]/2, self.size[1]/2-100), size=scene.Size(150, 75), action=my_button_action) self.my_button_left=ButtonNode( text='left', parent=self, position=scene.Point(self.size[0]/2-100, self.size[1]/2), size=scene.Size(150, 75), action=my_button_action) def touch_began(self, touch): EventHandler.touch_began(touch) scene.run(main())
ui.button
is much faster.. but by usingscene
i had 100% control of the design of the button.note: dont know if you recognise
EventHandler
class but i use a control class like this all the time. you can also just use your Scene's touch methods to and cut out the extra step. sorry if that created confusionyou can run both if you like to use
ui
you can create ascene.SceneView
and link it to your Scene class then add it to your MainViews subviews then you have both π.
Aside from explaining quickly about
scene
andui
the example for aButtonNode
should also help you with your curent situation ππ Enjoy! -
-
@cvp said:
I disagree. ui is wonderful π
oh yes it is very womderful but π€« dont tell
scene
i said anything... she has quite the temper.. π¬