Slider control in Cocos2d-X, cocos2d-xslider

Source: Internet
Author: User

Slider control in Cocos2d-X, cocos2d-xslider
The Slider control is actually a Slider control, which is often used in Music volume control. You need to use the Slider control to control the volume when developing a music player in Windows programming.

First, put




Add the following code in 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


Add the following code in Skider. cpp:

# Include "Slider. h "CCScene * Slider: scene () {CCScene * s = CCScene: create (); Slider * layer = Slider: create (); s-> addChild (layer); return s;} bool Slider: init () {// initialize the parent class CCLayer: init (); // obtain the window size CCSize winSize = CCDirector ctor: shareddire()-> getWinSize (); // create a slider CCControlSlider * slider = CCControlSlider: create ("sliderTrack.png ", "sliderProgress.png", "sliderThumb.png"); // Add the slider addChild (slider); // set the slider position slider-> setPosition (ccp (winSize. width/2, winSize. height/2); // you can specify the minimum slider value for the slider sliding range> setMinimumValue (0); // you can specify the maximum value of the slider> setMaximumValue (100 ); // set the maximum value when sliding the slider. This function is often used in movie slider-> setMaximumAllowedValue (90) of Free videos on video websites. // you can specify the minimum value when sliding the slider, this function is commonly used in movie slider-> setMinimumAllowedValue (10) for Free videos on video websites; // slider response function (call the ValueChanged function when the slider slides) slider-> addTargetWithActionForControlEvents (this, cccontrol_selector (Slider: ValueChanged), CCControlEventValueChanged); return true;} void Slider: ValueChanged (CCObject * sender, CCControlEvent ev) {// if (ev = CCControlEventValueChanged) {CCControlSlider * slider = (CCControlSlider *) sender when the slider slides; // obtain the slider value float f = slider-> getValue (); // print the slider value CCLog ("current value is % f", f );}}

Execution result:


Test running effect:

Bytes

Zookeeper
An error occurred while executing the statement CCControlSlider * slider in cocos2dx.

The header file is not imported or the namespace is not used.
 
How to Use the slider control in VB to control controls

Simply write such a piece of code to see if it can achieve the expected results!

1. Add a Slider control to the form, two PictureBox controls, Picture1 and Picture2;
2. Set the picture2 picture attribute in the Properties window to load a background image of the appropriate size. Set the visible attribute of picture2 to false.

The Code is as follows:
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.