Cocos2d-X中的Slider控制項,cocos2d-xslider

來源:互聯網
上載者:User

Cocos2d-X中的Slider控制項,cocos2d-xslider
Slider控制項其實就是滑塊控制項,常用於音樂中的音量控制,在Windows編程中開發音樂播放器就需要用到滑塊控制項控制音量

首先在工程目錄下的Resource檔案夾中放




在Skider.h添加下面的代碼

#ifndef __Slider_H__#define __Slider_H__#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class Slider : public CCLayer{public:static CCScene* scene();CREATE_FUNC(Slider);bool init();void ValueChanged(CCObject*, CCControlEvent);};#endif


在Skider.cpp添加下面的代碼

#include "Slider.h"CCScene* Slider::scene(){CCScene* s = CCScene::create();Slider* layer = Slider::create();s->addChild(layer);return s;}bool Slider::init(){    //初始化父類    CCLayer::init();    //得到視窗的尺寸CCSize winSize = CCDirector::sharedDirector()->getWinSize();       //建立一個滑塊    CCControlSlider* slider = CCControlSlider::create("sliderTrack.png", "sliderProgress.png", "sliderThumb.png");    //添加滑塊    addChild(slider);    //設定滑塊的位置    slider->setPosition(ccp(winSize.width / 2, winSize.height / 2));    //設定滑塊滑動範圍的最小值slider->setMinimumValue(0);    //設定滑塊的最大值slider->setMaximumValue(100);            //設定滑塊滑動時的最大值,此功能常用於視頻網站中的免費試看的電影slider->setMaximumAllowedValue(90);    //設定滑塊滑動的最小值,此功能常用於視頻網站中的免費試看的電影slider->setMinimumAllowedValue(10);    //滑塊響應函數(當滑塊滑動時調用ValueChanged函數)slider->addTargetWithActionForControlEvents(this, cccontrol_selector(Slider::ValueChanged), CCControlEventValueChanged);return true;}void Slider::ValueChanged(CCObject* sender, CCControlEvent ev){    //當滑塊滑動時if (ev == CCControlEventValueChanged){CCControlSlider* slider = (CCControlSlider*)sender;        //得到滑塊的值        float f = slider->getValue();        //列印滑塊的值        CCLog("current value is %f", f);}}

執行結果:


測試回合效果:




cocos2dx中語句CCControlSlider *slider出錯

沒匯入標頭檔 還是沒使用 命名空間
 
怎使用VB中的slider控制項控制控制項

簡單的寫了這麼一段代碼,看是不是能達到你所期望的結果!

1、在表單中添加一個Slider控制項,兩個PictureBox控制項,即:Picture1 和 Picture2;
2、在屬性視窗中設定picture2的picture屬性,即載入一張大小合適的背景映像;同時設定picture2的visible屬性為false

代碼如下:
Dim x1 As Long, y1 As Long
Dim x2 As Long, y2 As Long
Dim p As Long

Private Sub Form_Load()
Picture1.ForeColor = vbRed
Slider1.Min = 0
Slider1.Max = 100
x1 = 100: y1 = 100
x2 = 500: y2 = 500
Picture1.Line (x1, y1)-(x2, y2), , B
p = 0
End Sub

Private Sub Slider1_Scroll()
Picture1.PaintPicture Picture2.Picture, 0, 0, , , , , , , vbSrcCopy
If Slider1.Value > p Then
x2 = x2 + Slider1.Value
y2 = y2 + Slider1.Value
Else
x2 = x2 - Slider1.Value
y2 = y2 - Slider1.Value
End If
p = Slider1.Value
Picture1.Line (x1, y1)-(x2, y2), , B
End Sub
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.