当前位置: 首页>>代码示例>>Python>>正文


Python Image.collide_point方法代码示例

本文整理汇总了Python中kivy.uix.image.Image.collide_point方法的典型用法代码示例。如果您正苦于以下问题:Python Image.collide_point方法的具体用法?Python Image.collide_point怎么用?Python Image.collide_point使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kivy.uix.image.Image的用法示例。


在下文中一共展示了Image.collide_point方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GameOverDlg

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]
class GameOverDlg(Popup):

    def __init__(self, **kw):
        super(GameOverDlg, self).__init__(**kw)
        self.content = GridLayout(rows=4)
        self.title = 'Rainballz'
        self.content.add_widget(Label(
            text='GAME OVER',
            font_name='font/Mouser 3D.ttf',
            font_size=60))
        self.content.add_widget(Label(
            text='SCORE: ' + str(kw['score']),
            font_name='font/Mouser 3D.ttf',
            font_size=60))
        self.content.add_widget(Label(
            text='CONTINUE?',
            font_name='font/Mouser 3D.ttf',
            font_size=60))
        self.bl_btns = GridLayout(cols=2)
        self.img_yes = Image(source='img/yes_gray.png', size_hint=(.5, .5))
        self.img_no = Image(source='img/no_gray.png', size_hint=(.5, .5))
        self.bl_btns.add_widget(self.img_yes)
        self.bl_btns.add_widget(self.img_no)
        self.content.add_widget(self.bl_btns)
        self.timeout = False
        Clock.schedule_once(self.set_timeout, 2)

    def set_timeout(self, *args):
        self.timeout = True
        self.img_yes.source='img/yes.png'
        self.img_no.source='img/no.png'

    def on_touch_down(self, touch):
        if self.timeout:
            app = App.get_running_app()
            if self.img_no.collide_point(*touch.pos):
                app.stop()
            elif self.img_yes.collide_point(*touch.pos):
                wnd = app.root_window
                for child in wnd.children:
                    wnd.remove_widget(child)
                    del child
                from rootwidget import RootWidget
                wnd.add_widget(RootWidget())
开发者ID:victor-rene,项目名称:ld-rainballz,代码行数:46,代码来源:gameoverdlg.py

示例2: MyImage

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]
class MyImage(Scatter):
    def __init__(self, no, **kwargs):
        super(MyImage, self).__init__(**kwargs)
	self.no = no
	self.image = Image(source="bluerose.png")
	self.add_widget(self.image)
	self.size_hint = None, None
	self.width = 140
	self.height = 140
	self.pos = 400-70+random.randint(-200,200), 300-70+random.randint(-150,150)

    def on_touch_down(self, touch):
	if self.image.collide_point( *touch.pos):
		print self.no
	else:
		print "failed", self.no
	return super(MyImage, self).on_touch_down(touch)
开发者ID:ik486,项目名称:kivy_examples,代码行数:19,代码来源:z.py

示例3: Game

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]
class Game(Widget):
    def __init__(self):
        super(Game, self).__init__()
        self.map = tmx.TileMapWidget('images/platformer.tmx', Window.size, params.scale)
        self.add_widget(self.map)
        spawn = self.map.map.layers['objects'].find('spawn')[0]
        self.player = Player((spawn.px, spawn.py), self.map.map)
        self.map.add_widget(self.player)        # add to map so it's scrolled
        Clock.schedule_interval(self.update, 1.0/60.0)

        if True: #platform() == 'android':
            self.left_button = Image(allow_stretch=True, source='images/left-arrow-button.png',
                                     size=(sp(60), sp(60)), pos=(sp(10), sp(10)))
            self.add_widget(self.left_button)
            self.right_button = Image(allow_stretch=True, source='images/right-arrow-button.png',
                                     size=(sp(60), sp(60)), pos=(sp(80), sp(10)))
            self.add_widget(self.right_button)
            self.jump_button = Image(allow_stretch=True, source='images/up-arrow-button.png',
                                     size=(sp(60), sp(60)), pos=(Window.width - sp(70), sp(10)))
            self.add_widget(self.jump_button)

    def update(self, *ignore):
        self.player.update()
        self.map.set_focus(*self.player.pos)

    def on_touch_down(self, touch):
        if self.left_button.collide_point(touch.x, touch.y):
            keys[Keyboard.keycodes['left']] = True
        elif self.right_button.collide_point(touch.x, touch.y):
            keys[Keyboard.keycodes['right']] = True
        elif self.jump_button.collide_point(touch.x, touch.y):
            keys[Keyboard.keycodes['spacebar']] = True

    def on_touch_up(self, touch):
        if self.left_button.collide_point(touch.ox, touch.oy):
            keys[Keyboard.keycodes['left']] = False
        elif self.right_button.collide_point(touch.ox, touch.oy):
            keys[Keyboard.keycodes['right']] = False
        elif self.jump_button.collide_point(touch.ox, touch.oy):
            keys[Keyboard.keycodes['spacebar']] = False
开发者ID:D-Cipher,项目名称:My-Courses-repo,代码行数:42,代码来源:platformer.py

示例4: CoreTask

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]

#.........这里部分代码省略.........
        self.manyman.comm.move_task(self)
        self.unbind_all_buttons()

    def set_output(self, output):
        """Append the new output to the previous output."""
        self._out += output

        if self.manyman.settings['output_to_file']:
            # Write output to a file
            if not isdir(self.manyman.settings['output_folder']):
                mkdir(self.manyman.settings['output_folder'])
            f = open(self.outfile, "a")
            f.write("".join(output))
            f.close()

        if not self.info_showing:
            # Do not render output when the info popup is hidden
            return

        # Determine if the output window should scroll down or not
        scroll_down = self.scroll.scroll_y == 0 or \
            self.output.text == NO_OUTPUT_TEXT

        # Show the last lines of the output
        self.output.text = "".join(
            self._out[-self.manyman.settings['output_buffer_size']:]
        )
        if scroll_down:
            self.scroll.scroll_y = 0

    def on_touch_down(self, touch):
        """Handler when a task is touched. Checks for button presses first."""
        x, y = touch.x, touch.y
        if self.info_button.collide_point(x, y):
            self.info_button.color = (.9, .6, 0, 1)
            self.show_info()
            return False

        if not self.status == "Running":
            return False

        if not super(CoreTask, self).on_touch_down(touch):
            return False

        return True

    def on_touch_move(self, touch):
        """Handler when a task is moved."""
        if not self.status == "Running":
            return False

        if not super(CoreTask, self).on_touch_move(touch):
            return False

        self.info_button.color = (.8, .8, .8, 1)

        return True

    def on_touch_up(self, touch):
        """
        Handler when a task is released. Moves the task if released on a core,
        stops it otherwise.
        """
        x, y = touch.x, touch.y
        self.info_button.color = (.8, .8, .8, 1)
        if self.info_button.collide_point(x, y):
开发者ID:FlorisTurkenburg,项目名称:ManyMan,代码行数:70,代码来源:task.py

示例5: PendingTask

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]
class PendingTask(Task):
    """Widget for tasks in the pending tasks list."""

    def __init__(self, name, tid, manyman, **kwargs):
        Logger.debug("PendingTask: Inited pendingtask %s" % name)

        self.tid = tid
        self.command = kwargs.get('command', '')

        self.dup_button = None
        self.start_button = None

        super(PendingTask, self).__init__(name, manyman, **kwargs)

        self._build()

    def _build(self):
        """Render the PendingTask."""
        self.dup_button = Image(
            source=self.manyman.settings['task_dup_image'],
            color=(.8, .8, .8, 1),
            size_hint=(None, None),
            size=(40, 40)
        )
        self.layout.add_widget(self.dup_button)

        self.label = Label(
            text="AAAAAAAAAAAAAA",
            halign='center'
        )
        self.layout.add_widget(self.label)

        self.start_button = Image(
            source=self.manyman.settings['task_start_image'],
            color=(.8, .8, .8, 1),
            size_hint=(None, None),
            size=(40, 40)
        )
        self.layout.add_widget(self.start_button)

        self.bind(
            pos=self.update_graphics_pos,
            size=self.update_graphics_size
        )
        self.update_graphics_pos(self, self.pos)
        self.update_graphics_size(self, self.size)

        # Force Kivy to render the labels
        self.label.text = "AAADSldjbdejhvdsaf"

        if self.is_new():
            self.label.text = "%s\nNew" % self.name
        else:
            self.label.text = "%s\nStopped" % self.name

    def is_new(self):
        """Determine whether a task is new or stopped."""
        return self.tid[0] == 'P'

    def on_touch_down(self, touch):
        """Handler when a task is touched. Checks for button touches first."""
        x, y = touch.x, touch.y
        if self.dup_button.collide_point(x, y):
            # Duplicate the task
            self.dup_button.color = (.9, .6, 0, 1)
            Logger.debug("PendingTask: Duplicating task %s" % self.tid)
            if self.is_new():
                self.manyman.new_task(self.command, self.name)
            else:
                self.manyman.comm.duplicate_task(self.tid)
            return False
        if self.start_button.collide_point(x, y):
            # Smart-start the task
            self.start_button.color = (.9, .6, 0, 1)
            if self.is_new():
                self.manyman.comm.start_task(self.name, self.command)
            else:
                self.manyman.comm.move_task(self)
            self.parent.remove_widget(self)
            return False

        if not super(PendingTask, self).on_touch_down(touch):
            return False

        return True

    def on_touch_move(self, touch):
        """Handler when a task is dragged. Reset the button colors."""
        if not super(PendingTask, self).on_touch_move(touch):
            return False

        self.dup_button.color = (.8, .8, .8, 1)
        self.start_button.color = (.8, .8, .8, 1)

        return True

    def on_touch_up(self, touch):
        """
        Handler when a task is released. Starts the task on the core it was
        released on (if any).
#.........这里部分代码省略.........
开发者ID:FlorisTurkenburg,项目名称:ManyMan,代码行数:103,代码来源:task.py

示例6: AppLauncherIconWidget

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]
class AppLauncherIconWidget(GridLayout):
    """
        Displays icon and name of a single application
        Also handles input on the app icon
    """

    __imageParent = None  # type: AnchorLayout
    __imageWidget = None  # type: ImageWidget
    __nameWidget = None  # type: Label

    __starter = None  # type: AppStarter

    __paddingTmp = -1  # type: int
    __touched = False  # type: int

    def __init__(self, image: Image, name: str, starter: AppStarter, height: int, **kwargs):
        super(AppLauncherIconWidget, self).__init__(**kwargs)

        self.__starter = starter

        self.cols = 1
        self.rows = 2

        self.rows_minimum[0] = height * 0.8
        self.rows_minimum[1] = height - self.rows_minimum[0]

        self.row_force_default = True

        self.__imageParent = AnchorLayout()
        self.__imageParent.anchor_x = 'center'
        self.__imageParent.anchor_y = 'center'

        self.__imageWidget = ImageWidget()
        self.__imageWidget.allow_stretch = True
        self.__imageWidget.keep_ratio = True
        self.__imageWidget.texture = image.texture

        self.__nameWidget = Label()
        self.__nameWidget.text = name
        self.__nameWidget.color = [0, 0, 0, 1]

        self.__imageParent.add_widget(self.__imageWidget)
        self.add_widget(self.__imageParent)
        self.add_widget(self.__nameWidget)

    def set_image_size(self, size: int, percentage: float):
        if self.__paddingTmp is -1:
            self.__imageParent.padding = [(size - (size * percentage)) / 2, (size - (size * percentage)) / 2, (size - (size * percentage)) / 2, (size - (size * percentage)) / 2]
        else:
            self.__paddingTmp = (size - (size * percentage)) / 2

    def on_touch_down(self, touch):
        if self.__imageWidget.collide_point(*touch.pos):
            self.__touched = True
            self.__paddingTmp = self.__imageParent.padding[0]
            self.__imageParent.padding = [self.__paddingTmp * 1 / 0.8, self.__paddingTmp * 1 / 0.8, self.__paddingTmp * 1 / 0.8, self.__paddingTmp * 1 / 0.8]
        else:
            self.__touched = False

    def on_touch_up(self, touch):
        if self.__imageParent.collide_point(*touch.pos):
            self.__starter.start_app()

        self.__imageParent.padding = [self.__paddingTmp, self.__paddingTmp, self.__paddingTmp, self.__paddingTmp]
        self.__paddingTmp = -1
        self.__touched = False
开发者ID:Silveryard,项目名称:SmartHome,代码行数:68,代码来源:AppLauncherIconWidget.py

示例7: SettingPos

# 需要导入模块: from kivy.uix.image import Image [as 别名]
# 或者: from kivy.uix.image.Image import collide_point [as 别名]
class SettingPos(SettingString):
    '''Implementation of a string setting on top of a :class:`SettingItem`.
    It is visualized with a :class:`~kivy.uix.label.Label` widget that, when
    clicked, will open a :class:`~kivy.uix.popup.Popup` with a
    :class:`~kivy.uix.textinput.Textinput` so the user can enter a custom
    value.
    '''

    popup = ObjectProperty(None, allownone=True)
    '''(internal) Used to store the current popup when it's shown.

    :attr:`popup` is an :class:`~kivy.properties.ObjectProperty` and defaults
    to None.
    '''

#     position = ObjectProperty(None)
    '''(internal) Used to store the current textinput from the popup and
    to listen for changes.

    :attr:`textinput` is an :class:`~kivy.properties.ObjectProperty` and
    defaults to None.
    '''
    pic = StringProperty()
    position = StringProperty('50*50')

    def __init__(self, **kwargs):
        super(SettingPos, self).__init__(**kwargs)
        self.img = Image(source=self.pic)

    def on_panel(self, instance, value):
        if value is None:
            return
        self.bind(on_release=self._create_popup)

    def _dismiss(self, *largs):
        if self.popup:
            self.popup.dismiss()
        self.popup = None

    def _register(self, instance, touch):
        if self.img.collide_point(*touch.pos):
            #             self.position = '*'.join([str(p) for p in touch.pos])
            #             print(touch)
            #             print(self.img.pos)
            #             print(self.img.size)
            #             print(Window.size)
            x, y = self.img.to_widget(touch.pos[0], touch.pos[1], True)
            x = x - self.img.pos[0] - 20.0
            y = y + 68.0
#             print('%s * %s' % (x, y))
            self.position = str(x) + '*' + str(y)

    def _validate(self, instance):
        value = self.position
        self.value = value
#         print(self.value)
        self._dismiss()

    def _create_popup(self, instance):
        # create popup layout
        content = BoxLayout(orientation='vertical', spacing='5dp')
#         popup_width = min(0.95 * Window.width, dp(500))
        self.popup = popup = Popup(
            title=self.title, content=content)
        pos = [float(c) for c in self.value.split('*')]
        scat = ScatterCross(size=(20, 20), size_hint=(None, None), pos=pos)
        scat.bind(on_touch_up=self._register)
        self.img.add_widget(scat)
        content.add_widget(self.img)
        content.add_widget(SettingSpacer())

        # 2 buttons are created for accept or cancel the current value
        btnlayout = BoxLayout(size_hint_y=None, height='50dp', spacing='5dp')
        btn = Button(text='Ok')
        btn.bind(on_release=self._validate)
        btnlayout.add_widget(btn)
        btn = Button(text='Cancel')
        btn.bind(on_release=self._dismiss)
        btnlayout.add_widget(btn)
        content.add_widget(btnlayout)

        # all done, open the popup !
        popup.open()
开发者ID:bverdu,项目名称:onDemand,代码行数:85,代码来源:widgets.py


注:本文中的kivy.uix.image.Image.collide_point方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。