@omz Thank you.
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.

Posts made by Sketo
-
RE: Understanding TextField
@technoway WOW that is way more than I expected! Thank you so much for these references. I will dig in.
-
Understanding TextField
Once I place a TextField on the grid in the .pyui editor, what does the script in the .py file look like to retrieve the text input by the user? An example would be great.
I understand the action attribute that shows when you place a button on the grid but action does not show on a TextField, so Iām not sure how to make it call a function, like button, or store the user input.
Any help would be great.
-
RE: How to compare SpriteNode.textures
@JonB Thank you for responding also. These are both very helpful options.
-
RE: How to compare SpriteNode.textures
@omz Thank you for responding! This is very helpful.
-
How to compare SpriteNode.textures
How do I retrieve just the texture of a SpriteNode so that I can compare it to another?
When I compare sprite1's texture to sprite2's texture it always returns False even though I know they are the same texture.
I am assuming that I am comparing something other then the textures of sprite1 and sprite2.
How do I compare the textures so that if both sprites are 'plc:Brown_Block' then it returns True?
from scene import * sprite1 = SpriteNode('plc:Brown_Block') sprite2 = SpriteNode('plc:Brown_Block') print(sprite1.texture == sprite2.texture) False
-
RE: (How to) Spritesheet subtexture
It took me a while to figure out how to use a spritesheet but I finally figured it out. I wanted to post a small example that shows how it works. If I had something like this at the beginning when I was looking then I would not have wasted so much time searching and trying to figure it out. As a beginner just starting to understand these ideas, I want to help those like me searching for hours trying to find an example that makes it easy to understand for beginners.
I hope this helps the next new comer.The Rect(?,?,?,?) parameter describes the portion of the texture in unit coordinates, e.g. (0, 0, 0.5, 0.5) would create a texture from the bottom-left quarter of the original texture. (0,0) being the bottom left corner to half of the overall height (.5) of the texture and half of the overall width (.5) of the texture.
from scene import * x,y,xs,ys = 0,0,1,1 # š¼ Above sets up the initial subtexture(Rect(x,y,xs,ys)) on line 25 to show the full image until touch_began and touch_ended changes the coordinates of the subtexture to show whatever section you set in touch began. class MyScene (Scene): def setup(self): self.background_color = 'black' self.texture_name = SpriteNode(Texture('test:Mandrill'), scale = 2, position = self.size / 2, parent = self) def touch_began(self, touch): global x,y,xs,ys #These variables must be referenced as global or they will not be recognized. x,y,xs,ys = 0,0,.5,1 #This changes the coordinates for update() on line 25 to show a portion of the texture. def touch_ended(self, touch): global x,y,xs,ys #These variables must be referenced as global or they will not be recognized. x,y,xs,ys = 0,0,1,1 #This changes the coordinates back to show the full image when you stop touching the screen. def update(self): self.texture_name.texture = Texture('test:Mandrill').subtexture(Rect(x,y,xs,ys)) #This updates the Texture according to the cooridantes set by touch_began (line 17) and touch_ended (line 22). run(MyScene())``` One of the things that was making it hard for me to understand was that after initially setting up the Texture, on line 9, I thought you could simply reference the subtexture() directly like this... self.texture_name.texture.subtexture = Rect(?,?,?,?) OR self.texture_name.subtexture = Rect(?,?,?,?) ... but this was not working and it racked my brain for a while. Then I tried this... self.texture_name.texture = Texture('test:Mandrill').subtexture(Rect(?,?,?,?)) ... and found out that you must set, not just the subtexture, but the Texture and subtexture to the variable (self.texture_name.texture) before it's updated.
-
RE: (How to) Spritesheet subtexture
@omz WOW do I feel dumb. Thank you. I feel terrible for wasting your time for something so small but thank you again.
-
RE: (How to) Spritesheet subtexture
@omz Another question if you don't mind. Update should change from gem_texture[0], in setup, to gem_texture[3], in update(). Its not changing it... is this not possible or am I missing something?
from scene import * gem_texture = [ Texture('plc:Gem_Orange').subtexture(Rect(0,.5,.5,.5)), Texture('plc:Gem_Orange').subtexture(Rect(.5,.5,.5,.5)), Texture('plc:Gem_Orange').subtexture(Rect(0,0,.5,.5)), Texture('plc:Gem_Orange').subtexture(Rect(.5,0,.5,.5)), ] class MyScene (Scene): def setup(self): self.background_color = 'black' self.gem = SpriteNode(gem_texture[0], scale = 4, position = self.size / 2, parent = self) def touch_began(self, touch): pass def update(self): #Fixed case correction # Update should change from gem_texture[0], in setup, to gem_texture[3], in update(). Its not changing it... is this not possible or am I missing something? self.gem.texture = gem_texture[3]```
-
RE: (How to) Spritesheet subtexture
@omz Thank you for your reply. I was hoping it would be easier, sense it is only a reference to a section of the sprite sheet. It seams as though you could just change the reference coordinates to show a different part without having to make a new object. But again thank you for clearing this up for me.
-
(How to) Spritesheet subtexture
I finally found out how to use the Texture.subtexture() to get a portion of a spritesheet on the scene. Now, after the initial setup of the subtexture, I'm having trouble figuring out how to change the position of the shown section to a new section after the initial setup.
Do I have to create individual SpriteNodes for each section of the spritesheet? I'm hoping there is an easier way.
Im hoping there is a way to update the coordinates in subtexture(Rect(?,?,?,?)) to show a new portion of the spritesheet.If anyone knows how to do this I would appreciate any help. Thank you!
from scene import * class MyScene (Scene): def setup(self): self.background_color = 'black' self.sprite_sheet = SpriteNode() self.sprite_sheet.position = self.size / 2 self.sprite_sheet.scale = 2 self.sprite_sheet.texture = Texture('plc:Gem_Orange').subtexture(Rect(0,0,.5,.5)) self.add_child(self.sprite_sheet) def touch_began(self, touch): pass def Update(self): pass run(MyScene(), show_fps = True)```
-
RE: (How to) Virtual d-pad that moves a sprite only when screen touched.
@abcabc Thank you very much for this. You have shown me a new way that seams to make the motion smoother. Thank you again.
-
RE: (How to) Virtual d-pad that moves a sprite only when screen touched.
@abcabc Thank you for the reply. If you don't mind me asking... how do you achieve this with the Action method?
-
(How to) Virtual d-pad that moves a sprite only when screen touched.
Maybe someone knows a better way but I'm trying to test a way to move a sprite around the screen using a virtual d-pad at bottom left of the screen. I tried creating a global variable that is set to 0 at the beginning. When you touch the screen it changes to 1 and when you stop touching the screen it changes back to 0 again.
In update() I expected touch() to change the global variable on the fly but it just does not work like I thought. Any help would be appreciated.
from scene import * import sound # Global variable that will be changed when you touch the screen. sp = 0 class MyScene (Scene): def setup(self): self.background_color = 'midnightblue' self.ship = SpriteNode('spc:PlayerShip1Orange') self.ship.position = self.size / 2 self.add_child(self.ship) def touch_began(self, touch): if touch.location < 100: # when the screen is touched then the global variable changes to 1 and should update the movement of the ship in update()... but ship movement does not change. sp = 1 def touch_ended(self, touch): if touch.location < 100: # i was hoping that once touch_began() started moving ship, that touch_ended() would stop movement so that it works like a simple directional pad. sp = 0 def update(self): pos = self.ship.position '''pos += x + sp, y + sp''' #this is just a test to see if touch would change the global variable "sp" and update accordingly. If i change it on line 4 it will update and move the ship. I dont know how to alter sp on the fly to move ship with touch until i stop touching the screen. like a controler moving mario or something. pos.y += sp # Don't allow the ship to move beyond the screen bounds: pos.x = max(0, min(self.size.w, pos.x)) pos.y = max(0, min(self.size.h, pos.y)) self.ship.position = pos run(MyScene(), PORTRAIT)```