from scene import *
import sound
import random
import math
A = Action
sprite_sheet=[Texture('scene_practice/new_sprites/IMG_3039.JPG').subtexture(Rect(0,0.5,0.33,0.25)),Texture('scene_practice/new_sprites/IMG_3039.JPG').subtexture(Rect(0.33,0.5,0.33,0.25)),Texture('scene_practice/new_sprites/IMG_3039.JPG').subtexture(Rect(0.66,0.5,0.33,0.25))]
class MyScene (Scene):
def setup(self):
self.screen="game"
self.background_color = 'black'
self.Sprite = SpriteNode(sprite_sheet[0],scale = 4, position = (self.size.x/2,self.size.y/1.1), parent = self)
self.add_child(self.Sprite)
self.n = -1
self.button = SpriteNode('shp:Circle',scale=2,position=(self.size.x/1.5,self.size.y/3))
self.add_child(self.button)
def did_change_size(self):
pass
def update(self):
step1 = int(self.Sprite.position.y / 15) % 3
if step1 != self.n:
self.Sprite.texture = sprite_sheet[step1]
def touch_began(self, touch):
moveaction = Action.move_by(0,-46)
if touch.location in self.button.bbox:
self.Sprite.run_action(moveaction)
if __name__ == '__main__':
run(MyScene(), show_fps=False)
Okay so here is a basic version of what I have been doing.
So in my Update method I’m using the y coordinate of my sprite to return an integer 0 or 1 or 2, then I’m using this as a reference To set the texture from my spritesheet, basically just what was being done in the game tutorial.
The thing I’m stuck with is how I can expand this idea to another direction, so for instance if I wanted to go up instead of down I would need to use an entirely different sprite sheet but I don’t know how to do that
What I would really like to do if possible is tie the whole animation process to the button press so I could animate a more diverse range of things not just relying on position? Does that make sense?
I’m so grateful for you guys taking time to read my stuff and help, gives me real motivation to keep learning, so thanks again everyone