Cocos2d-x 3.2 Lua Sample cocosdenshiontest (audio test)

Source: Internet
Author: User
Tags lua

https://blog.csdn.net/wwj_748/article/details/38588563

Cocos2d-x 3.2 Lua Sample cocosdenshiontest (audio test)

This blog describes the audio tests of the LUA example in Cocos2d-x 3.2, Cocos2d-x uses Simpleaudioengine to control audio, such as playback, pausing, stopping, and so on. In the LUA code, the Audioengine is used, the implementation can refer to the Audioengine.lua file, but the simpleaudioengin is encapsulated.

Sample code:
[JavaScript]  View plain  copy--[[   cocosdenshiontest.lua   cocos2d-x  Audio Support   ]]--& nbsp;  require  "Audioengine"    local effect_file =  "Effect1.wav"         local music_file = nil  --  get target platform    local  TARGETPLATFORM = CC. Application:getinstance (): Gettargetplatform ()   -- iphone or ipad   if  (cc. Platform_os_iphone == targetplatform)  or  (CC. Platform_os_ipad == targetplatform)  then     MUSIC_FILE =  " BACKGROUND.CAF " -- CAF format    else     MUSIC_FILE = " Background.mp3 " -- mp3 format    end      local line_space = 40        local function cocosdenshiontest ()      local  RET = CC. Layer:create ()      local m_pItmeMenu = nil     local m_tbeginpos =  CC.P (0, 0)      local m_nSoundId = 0         --  Test Menu Items      local testItems = {         "Play background music",        "Stop background music",         "Pause background music",        " Resume background music ",       " Rewind background music ",         "is background music playing",         "Play effect",        "play effect repeatly",         "Stop effect",        "Unload effect",    &Nbsp;    "Add background music volume",        Sub  background music volume ",       " Add effects volume ",         "Sub effects volume",        Pause  effect ",       " Resume effect ",       " Pause all effects ",       " Resume all effects ",        "Stop all effects"      }         --  Menu callback Method      local function menucallback (Tag, pmenuitem)         local nidx = pmenuitem:getlocalzorder ()  - 10000        -- play background music       if  nidx ==  0 then         audioengine.playmusic (MUSIC_FILE,  true)  --  Play Music   

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.