Exemple #1
0
    def __init__(self):
        ShowBase.__init__(self)

        imageObject = OnscreenImage(image='me.png', pos=(-0.5, 0, 0.02))
        # Reparent the model to render.
        imageObject.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        imageObject.setScale(10, 10, 10)
        imageObject.setPos(0, 42, 0)

        car = OnscreenImage(image="car.png", pos=(0,0,0))
        car.reparent_to(self.render)
        car.setScale(3, 3, 3)
        car.setPos(0, 41, 0)

        self.accept('arrow_left-up', self.car_go_left, [car])
        self.accept('arrow_right-up', self.car_go_right, [car])
Exemple #2
0
class Cursor:
    def __init__(self, path, scale, hotspot):
        if not path:
            return
        self.__set_standard_curson(False)
        self.cursor_img = OnscreenImage(path)
        self.cursor_img.setTransparency(True)
        self.cursor_img.setScale(scale)
        self.cursor_img.setBin('gui-popup', 50)
        self.hotspot_dx = scale[0] * (1 - 2 * hotspot[0])
        self.hotspot_dy = scale[2] * (1 - 2 * hotspot[1])
        eng.event.attach(self.on_frame)

    def __set_standard_curson(self, show):
        props = WindowProperties()
        props.setCursorHidden(not show)
        base.win.requestProperties(props)

    def show(self):
        self.cursor_img.show()

    def show_standard(self):
        self.__set_standard_curson(True)

    def hide(self):
        self.cursor_img.hide()

    def hide_standard(self):
        self.__set_standard_curson(False)

    def cursor_top(self):
        self.cursor_img.reparent_to(self.cursor_img.get_parent())

    def on_frame(self):
        if base.mouseWatcherNode.hasMouse():
            x = base.mouseWatcherNode.getMouseX()
            y = base.mouseWatcherNode.getMouseY()
            h_x = x * base.getAspectRatio() + self.hotspot_dx
            self.cursor_img.setPos(h_x, 0, y - self.hotspot_dy)