Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Can I Change background by script ????!?!?!?!  (Read 3391 times)

0 Members and 1 Guest are viewing this topic.

Endrit

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 62
    • View Profile
Can I Change background by script ????!?!?!?!
« on: July 24, 2011, 03:51:16 PM »

Hi guys , ::wave
how are you ???
It's been some time since my last topic here (i'm working on my game) .
Well now i'm looking to do a "dynamic" background that change in random .
i'm going to explain my steps :
-Create a new scene (Room) and edit it
-click on the default beckground and select it and add a new empty script
-in the script i add the fallowing lines of code that i saw on the wikiWME

Code: [Select]
#include "scripts\base.inc"

//add a variable
var background ;
//give to the background var. some values
background [0] = "image0.jpg";
background [1] = "image1.jpg";
background [2] = "image2.jpg";

//add a random variable
var casual = Random (0,2);



And this is all what i learnd to do but now i don't know how to do the change !!!!
Can some one help me ???

Hope I was clear .....
Thx guys !!! :)   ::rock
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Can I Change background by script ????!?!?!?!
« Reply #1 on: July 24, 2011, 09:52:22 PM »

Now you need to find the entity that is the background of your scene.

You need to use Scene.GetNode("background") to get the background of your current scene and then change the sprite.

For instance your script could be:

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. //add a variable
  4. var background ;
  5. //give to the background var. some values
  6. background [0] = "scenes\scene1\image0.jpg";
  7. background [1] = "scenes\scene1\image1.jpg";
  8. background [2] = "scenes\scene1\image2.jpg";
  9.  
  10. //add a random variable
  11. var casual = Random (0,2);
  12.  
  13. var backgroundEntity = Scene.GetNode("background");
  14. var newBack = background[casual];
  15. backgroundEntity.SetSprite(newBack);
  16.  
  17.  
Logged

Endrit

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 62
    • View Profile
Re: Can I Change background by script ????!?!?!?!
« Reply #2 on: July 25, 2011, 11:57:42 AM »

Now you need to find the entity that is the background of your scene.

You need to use Scene.GetNode("background") to get the background of your current scene and then change the sprite.

For instance your script could be:

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. //add a variable
  4. var background ;
  5. //give to the background var. some values
  6. background [0] = "scenes\scene1\image0.jpg";
  7. background [1] = "scenes\scene1\image1.jpg";
  8. background [2] = "scenes\scene1\image2.jpg";
  9.  
  10. //add a random variable
  11. var casual = Random (0,2);
  12.  
  13. var backgroundEntity = Scene.GetNode("background");
  14. var newBack = background[casual];
  15. backgroundEntity.SetSprite(newBack);
  16.  
  17.  

Thanks you were very helpful !!!! :)
I'm going to use this system for the menu of the game !!!! ::rock
Logged
 

Page created in 0.047 seconds with 24 queries.