cocos2dx win32修改鼠标指针图案

本文介绍了如何在cocos2dx的Win32平台上利用glView的setCursorVisible方法,来实现修改鼠标指针图案的效果。在AppDelegate.cpp和自定义的layer中进行了操作说明。

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

win32的api实在太麻烦了,但是glView里面有个setCursorVisible的方法,可是借此实现同样的效果。

AppDelegate.cpp中:

glview = GLViewImpl::createWithFullScreen("123465");
glview->setCursorVisible(false);
director->setOpenGLView(glview);

自己的layer中:

//鼠标指针
auto cursor = Sprite::create("cursor_nor.png");
this->_cursor = Node::create();
this->_cursor->addChild(cursor);
this->addChild(this->_cursor,10000);

auto listenerMouse = EventListenerMouse::create();
    listenerMouse->onMouseMove = [&](cocos2d::EventMouse* event) {
        Point mouse = event->getLocation();
        mouse.y = 1024 - mouse.y;

        this->_cursor->setPosition(Point(mouse.x+20,mouse.y-30));
    };
    listenerMouse->onMouseDown = [&](cocos2d::EventMouse* event) {
        this->_cursor->removeAllChildren();
        auto cursor = Sprite::create("cursor_pre.png");
        this->_cursor->addChild(cursor);
    };
    listenerMouse->onMouseUp = [&](cocos2d::EventMouse* event) {
        this->_cursor->removeAllChildren();
        auto cursor = Sprite::create("cursor_nor.png");
        this->_cursor->addChild(cursor);
    };
    this->_eventDispatcher->addEventListenerWithFixedPriority(listenerMouse, 1);

Flag Counter

AI 时代程序员必备技能

Codex、Claude Code、Cursor、Hermes Agent、OpenClaw等工程化实战专栏 ,讲透 AI 如何接管脏活累活

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值