webOShelp.net

Get the latest on:webOS Developers' RSS FeedwebOS Facebook page webOS Twitter Feed

Home Forums
The webOShelp.net WebOS / Mojo Developers' Forum
September 30, 2014, 11:52:37 AM *
Welcome, Guest. Please login (using the form in the left column) or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: push a "random" scene w/button?  (Read 3905 times)
itsallsubliminal
webOS Newb
*
Offline Offline

Posts: 1


View Profile
« on: January 14, 2010, 12:33:34 PM »

Hey guys, i'm very new to programming all around the board, but seem to grab concepts pretty easily if someone explains.

I'm creating a simple app/game, but when I tap the "start" button on the main scene, I want it to push a random scene, mainly because i don't want the game to start with the same scene every time.

Is it more complicated than i thought? more than just a few lines of code?

Any help here would be greatly appreciated. Thanks!
Logged
maheshj86
webOS Newb
*
Offline Offline

Posts: 3


View Profile
« Reply #1 on: March 02, 2010, 10:59:12 PM »

You can have say five scenes - scene1, scene2, scene3, scene4, scene5 of which you might want to load one randomly. So now, you can load a scene with something like:

Code:
var num = 1 + Math.floor(Math.random()*4);
this.controller.pushScene('scene' + num);

If you cannot have the scenes named in numerical order, you can always have an array containing all the scene names and selecting one on button click randomly.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2009, Simple Machines LLC
SMF customization services by 2by2host.com
Valid XHTML 1.0! Valid CSS!