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
-
@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.. 😬 -
-
@cvp I didn’t said it’s bad
-
-
-
This post is deleted! -
You have 3 touch_began in the game that refer to each other and it's brainstorming) can you explain how it works all together?
def touch_began(cls, touch): if(cls.needsTouch): #i didn't see where you add smth into needsTouch for node in cls.needsTouch: node.touch_began(touch) cls.player.touch_began(touch) cls.allTouches.append(touch)
And you have here "if cls.needsTouch" but I didn't find where you add smth to the list
-
-
@Karina wow, if you check my post, the sentence about I spoke was "ui is not too bad", not at all something else. It was only a personal reaction about the fact that I find Pythonista's ui marvelous and not "not too bad". Nothing about scene.
-
-
@Karina Wonderfull Eye 😎🤓 lets look t wht we got here.
player=None needsTouch=[] allTouches=[] def touch_began(cls, touch): if(cls.needsTouch): for node in cls.needsTouch: node.touch_began(touch) cls.player.touch_began(touch) cls.allTouches.append(touch) def touch_moved(cls, touch): if(cls.needsTouch): for node in cls.needsTouch: node.touch_moved(touch) cls.player.touch_moved(touch) def touch_ended(cls, touch): if(cls.needsTouch): for node in cls.needsTouch: node.touch_ended(touch) cls.player.touch_ended(touch)
First id like to start with the fact i did miss somthing here initially.
Another was left purposly as a social excersise and other is for future use for Menu buttons. Ill explain 😊
cls.player.touch_began(touch)
this i completely missed... i forgot o do my Null check and if this were much large of game it would of crested issues. to fix this just add the check for it just like for
needsTouch
.... if(cls.player): cls.player.touch_ended(touch) ...
cls.needsTouch
here we are setting up touch to be used for objects such as Buttons for menus. since we do our
null check
it gets bypassed every time until we need it so in th future we can make a button object, just like we did yesterday withButtonNode
and here we usedEventHandler
, here instead we useEventManager
exact same use so from your buttond__init__
you useEventManager.needsTouch.append(self)
and insur your button has
def touch_began(self, touch):
Method nd all done. set all your touch logic from the button class just to keep everything separated would be my suggestion. 🤓
cls.allTouches.append(touch)
this one was left purposly to give an oprotunity for curiosity and get people to ask questions. exactly as you did.. 🤠 with out curiosity theres no advancement and without questions there no answers 😉. so 3 ⭐️⭐️⭐️ !!! 1 for
allTouches
and two for my null check misshap.
from here you cand add the null chek if you like and remove both
cls.allTouches.append(touch)
andallTouches=[]
. i would suggest keeping thecls.needsTouch
if you plan to build more on it but its your project 🤠😊 -
Aa, I thought maybe the modules do bugs in serious programs. But they are perfect match, no place to those things😉
-
So which of the touches needed for game or for future?
def touch_began(self, touch): self.ChangePose(1) self.idleJet.remove_from_parent() self.jetpack.add_child(self.liftJet) self.animate.Ascend(duration=0.15) if self.isDead != False: self.scene.gameOver=True self.isDead=True self.ChangePose(4)
And why you are ending the game in touch_began? He will be hit when touch began?