Random x and y coordinates
@ccc ended up using.
self.bubble.position = random.randrange(410), random.randrange(890)
ccc last edited by ccc
So what happens when you move your scene to a different device? iPad, iPad Mini, iPhone small screen, iPhone XL screen? Also, when you rotate the screen.
mikael last edited by
@resserone13, removing and then adding the bubble to the parent is unnecessary and makes no visual difference. Just change the position.
If you want a small delay between the bubble vanishing and popping up again, use Actions.
@ccc I’ve tried a few things but it keeps saying range expected a sequence.
self.bubble.position = ((*(random.randrange(x) for x in self.size)), (*(random.randrange(x) for x in self.size)))
@mikael I had trouble with action. I have a card game I’m working on and I can’t really figure out action or sequence. I was trying to have the cards shuffle around. With . Move_to(). I can get to to move once but no more and I can’t figure out sequence
mikael last edited by mikael
@resserone13, a little repeated code is not bad, if it makes things more understandable:
self.bubble.position = random.randrange(self.size.w), random.randrange(self.size.h)
@mikael thanks. That works and is simple. Can you show me an example of how to use actions and how to use sequence? Maybe make the bubble move twice each time it’s touched?
mikael last edited by
@resserone13, here’s an example, quickly adapted from the docs. To make progress on this, be sure to read at least all the intro bits of the scene module, and keep hitting the Help on the individual methods.
from random import randrange from scene import * class MyScene (Scene): bubble_radius = 40 bubble_diameter = bubble_radius * 2 def setup(self): self.background_color = 'midnightblue' self.bubble = SpriteNode('plf:HudCoin') self.bubble.position = self.size / 2 self.bubble.size = (self.bubble_diameter,) * 2 self.add_child(self.bubble) def touch_began(self, touch): # Hit detect if abs(self.bubble.position - touch.location) <= self.bubble_radius: new_position = randrange(self.size.w), randrange(self.size.h) self.bubble.run_action( Action.sequence( Action.fade_to(0, 0.3), Action.move_to(*new_position), Action.wait(0.1), Action.fade_to(1, 0.3), ) ) run(MyScene())
enceladus last edited by
Look at the following scene action examples in
@enceladus thanks for the info. I have looked through some of this. Mainly the card game. A lot of good stuff. My issue Sometimes is understanding what I’m reading. I believe it’s good to read code and I try to read as much as I can and watch videos and figure out everything I can buy myself and then after that I’ll post here.
@ccc would something like this be a good idea?
position = (self.size.w/2, self.size.h * 1.60)
If not would be so kind to so me the proper way.