Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Flashlight Help

Hey guys, Ive decided to try my hand at a mystery game and Ive actually gotten pretty excited about it, Ive done several searches on here and google for instructions on how to make a flashlight effect where I can get a beam normal ray (kinda like Legend of Zelda, link to the past, but in front of him)

I saw angel's process for making one but it was VX, tried opening up XP and like 'translating' to work on XP...no go there. So if someone could point me to an XP flashlight or something that would be great. I know ive clicked like 20 different topics and found nothing, and with dial-up its a pain to load all that for nothing :lol:

Only thing I would need help with is maybe somehow have a "battery" bar, but I think I could wing that with a conditional/variable/time combo.
 
this is a very tricky thing to do if you don't really know how to do it...I'm going to take a stab at it, but I can't test it from school :huh: .

The first thing you need is a picture of your flashlight. You can either make it an animation or just a picture but I am giong to use a picture for they way that I'm working through. You need to make your picture 1280 x 960 so that it fills your screen and has enough on each side so that you can go to the edge of your map. You should make the picture completley black, then create a white space where your light is. You need to make it in each of the four directions that you use, which isn't hard, just use the rotate function of paint. Name them Flashlight_Up , _Left, _Right, _Down, respectively. Then import them into XP and set white to the transparent color.

Then next step you need to do is to create a common event as a parallel process that uses a switch called Flashlight. Whenever you turn on your flashlight, set this switch to on. In your common event you need four different conditional branches. They all four use a script command that checks the player's direction. I don't remember them off the top of my head, but I'll check it once I get home and let you know what they are. Uncheck the box in the conditional branch the says set handleing if else applies or whatever it says so that it only runs when the conditions are met. Inside each of the conditional branches you want to use a show picture command to show the picture. I need to go now, but I'll edit this post when I get back with the last few details that you need. (a few variables I think...but I'm not 100% sure yet. I'll probably get you the code so that it moves based on the players X,and Y coords. I'll check it out and let you know how it finishes.

Good Luck!
~xgamexfreakx

(to be edited...)
 
You don't need a script command to check a player's direction in XP, at least.  And it's not quite that complicated.  You can assign a variable to equal the character's direction, and all you should need to do is Show Picture 1 (The player's screen X and Y, maybe offset slightly) of the different flashlight images depending on the value of the character's direction.  Just be sure to use an Erase Picture event when the player leaves the dark area. 

Would you like a screenshot?
 
I understand what he is talking about as far the conditional branches (I think lol) but when talking about the black screen and making a white box, im assuming in the center.

But ya, I could use a visual aid too.

Edit : I appreciate the help from both of you, i'll be back later to check on whats got to be done to get this light going.
 
ok, so I'm home now so I can actually help you out completely....so picking back up where I left off (and yes, you could do this Unka Josh's way, but this is just how I thought to do it on the spot.)

 
xgamexfreakx":2liw6y54 said:
this is a very tricky thing to do if you don't really know how to do it...I'm going to take a stab at it, but I can't test it from school :huh: .

The first thing you need is a picture of your flashlight. You can either make it an animation or just a picture but I am giong to use a picture for they way that I'm working through. You need to make your picture 1280 x 960 so that it fills your screen and has enough on each side so that you can go to the edge of your map. You should make the picture completley black, then create a white space where your light is. You need to make it in each of the four directions that you use, which isn't hard, just use the rotate function of paint. Name them Flashlight_Up , _Left, _Right, _Down, respectively. Then import them into XP and set white to the transparent color.

Ok, well... I did this for you just so I could test it myself, and just for refrence...don't use gradients. They don't work at all for this...(at least mine didn't...)

PICTURES!!!

First Make your picture of the flashlight beam...

http://i265.photobucket.com/albums/ii20 ... ght_Up.png[/img]

Then you import it and select white transparent when you import it...

http://i265.photobucket.com/albums/ii20 ... Import.png[/img]

And there is step 1!  (woot!  :thumb: )

xgamexfreakx":2liw6y54 said:
Then next step you need to do is to create a common event as a parallel process that uses a switch called Flashlight. Whenever you turn on your flashlight, set this switch to on. In your common event you need four different conditional branches. They all four use a script command that checks the player's direction. I don't remember them off the top of my head, but I'll check it once I get home and let you know what they are. Uncheck the box in the conditional branch the says set handleing if else applies or whatever it says so that it only runs when the conditions are met. Inside each of the conditional branches you want to use a show picture command to show the picture.

PICTURES!!! (again...)

Here is how you set up the conditional branch...

http://i265.photobucket.com/albums/ii20 ... Branch.png[/img]

And here is the common event so far...notice that the xy coords are not (0,0). They are set to (-320,-240). This sets the picture in the middle so that your character is centered in the light (or however you made you picture...)

http://i265.photobucket.com/albums/ii20 ... Event1.png[/img]

Now we get into the new stuff!

aaannndddd...the new stuff isn't working like I want it to. The problem is, you can't have the picture stay at certain coords and move with the player at the same time. It doesn't work that way. I've gotten it close. I'll edit once I get it fixed and working then I'll walk you through the rest.

Till then,
Good Luck!
~xgamexfreakx
 
As for the 3rd part with the moving, I could make a buffer space around like angel said, would that fix the problem with stuff moving with you? So that its always centered.

And im up to speed now, lol
 
Well, it moves with the character so that part works okay, it just isn't sitting with the visible area over the character. I can do that with coords, but I can't do that with variables. And as I was typing this I just got an idea. I'm gonna go see if it works.... :thumb:

Edit: I got it figured out now! First though, I would recommend using a circle for your light as it will make your life a lot easier...

Now I am going to completely rewrite all the steps, though I'm not going to take pics for the first two...(yes they will be different as I am going to make it a circle. If you want a beam, then let me know and I'll rewrite the code for a beam.)

Ok, so. Here it is! Hope you enjoy it.

The first thing you are going to do is make you picture with the circle. Here is mine if you want to use it.

http://i265.photobucket.com/albums/ii20 ... eLight.png[/img]


And that is all for step one. (yeah. easy huh?  :dead: )

ok, now you import the file and make sure that the the transparent color is white. I don't think you need a picture for that.
Now you follow the rest of the old step two, but I'll retype it anyways. Then next step you need to do is to create a common event as a parallel process that uses a switch called Flashlight. Whenever you turn on your flashlight, set this switch to on. In your common event you need four different conditional branches. They all four use a script command that checks the player's direction. The script code that you will be using is:
Code:
$game_player.direction == 2
.
Uncheck the box in the conditional branch the says set handling when conditions do not apply. Inside each of the conditional branches you want to use a show picture command to show the picture of your flash light. Set it to the Upper-Left and set the coords to (-320,-240). This doesn't really do anything I don't think except set up the picture to be moved. Here is your pic of what it'll look like so far.


http://i265.photobucket.com/albums/ii20 ... Event1.png[/img]


And that'll do it for step 2. I'll post this now and then edit straight away so that you can see that I am atleast doing something and not laughing at you waiting...

ok, now for the confusing part of all of this. I'll give you one picture of this at the end, so just try to hold on tight till then. (Also, since this is a circle light, you no longer need the direction check, so delete the conditional branch...   :blush: )

Now, after your picture command, you need to start a loop (this is a command on the bottom of the first column of the first page of event options). Inside that loop goes a lot of control variables so you'll need to pay attention here.
In this order, add:

Control Variables [????: Flashlight X] == -640
Control Variables [????: Flashlight Y] == -480
Control Variables [????: Player X] == Player's Map X
Control Variables [????: Player X] *= 30     (this mulitplies the player X variable by 30. Play with number till it fits you. 30 works on small maps)
Control Variables [????: Player Y] == Player's Map Y
Control Variables [????: Player Y] *= 30     (Just like before)
Control Variables [????: Flashlight X] += Variable Player X     (This add the value of Player X to Flashlight X)
Control Varialbes [????: Flashlight Y] += Variable Player Y     (As stated above)

There is all your variable commands. Quite a lot, heh???

Last few commands here.

Now you need your move picture command. So set it to move picture #1 in 4 frames (that's one step) the set it to variable Flashlight X and variable Flashlight Y. Now you do need a conditional branch. Set your conditional branch for Switch: [Flashlight Off] is On. Then inside that put these few commands.
Erase Picture 1
Control Switches [???: Flashlight Off]: Off
Control Switches [???: Flashlight]: Off
Jump to Label: End    (this keeps it from still repeating)

Then at the very end of everything make the label End.

This will do it for you! Here is your pic that explains most in one frame...

http://i265.photobucket.com/albums/ii20 ... ntdone.png[/img]


Edit: one thing that I forgot that I can't believe I did....
To start the flashlight, turn swith [Flashlight] : ON
To turn off the flashlight, turn switch [Flashlight Off] : ON
That should do it for ya.  :thumb:

Hope this helped!!!
Good Luck
~xgamexfreakx
 
Btw now that I look at this, I suppose I should have mentioned I only wanted it to show maybe 4-5 blocks ahead, would I need to go back and make these cones smaller or will I be able to just edit them within the game?

Edit : Well I would hope you wernt laughing :P
And I do appreciate the help a lot
 
ok. It's done and everything finished. Let me know if you have any more problems with it!!

Edit: If you want it in a cone, let me know and I'll recode it to fit for you. It's not that big of a prob!
 
Okay, I got all the stuff set exactly as you got it, took a bit of figuring out by finally got it lol.
Anyway, now that i have this, what do I do to go about getting the light to be turned on by simply hitting [shift] or something like that? and with that I'll be back in like 10mins
 
I made an item, made sure its in his inventory, only thing I need help with is this, is there a certain way I need to make the room dark in order for it to work, like using a screen tint to black? Or something else, I think this may be the only thing im missing to make it work right.

Yea, I do apologize if I seem to be an idiot at this but I only really know the basic, simple stuff of XP. (Making stories, skills, events) but when it comes to adding new stuff its like sending it to me in Spanish (which I barely passed) :lol:
 
Well, if you tinted the screen black, then you wouldn't be able to see anything at all because everything is already blacked out by the pic. I'd say just throw the switch for the flashlight as you walk into a dark room, but you could just create another common event that throws the switch and turns off the switch depending on whether it is already on or not. Just set the item so that when you use it it calls that common event. Just make sure to have the pic of your flashlight beam set and imported and put into the script. Use the circle one that I made if you want.

As for my variables, I shoulda used the players screen XY instead of the map XY  :dead: . Don't know why I didn't. I tend to overthink things and make them much more complicated, but that's the way I like to do things. In a long roundabout way that takes forever to come up with. I do think though that my way is a bit more fool proof (if you change the player XY to the screen XY and get rid of the *30) Then I think it would be just about perfect. The reason why I had to center the pic at (-640,-480) is so that the black would still be on the screen, even if you were to go to the very edge. Yours might work just like that too, I dunno.

Also, for just hitting a button, as said earlier by Unka Josh, just put a conditional branch like he has shown. The only thing I see with that is that you would have to hold down the key the entire time. Personally, I would put everything in a loop after the conditional branch so that once you press it, it will stay on. then you would just have another conditional branch that checks to see if you press the key again to shut it off (jump to label).    (If you want further explanation, don't hesitate to ask.)

So, like I said, I tend to do things in a roundabout way, but I try to cover everything in the process. As for using the script, I just like scripting because it's fun to say that you can script (even if it's only a line of code  :blush: ). I do know more though, not just that little bit. I used that on chests and things, plus I think that you could more easily manipulate that in the script editor if you wanted to. (I dunno why though...)

Well...Glad to have helped, whichever one you used.

Good Luck!
~xgamexfreakx
 
Im still not understanding this, Ive got it to where it will show a black screen with a white circle, which is a little off center, but the screen pops up without a button at all (which works too I suppose) but I can see my guy but cant move when the event is called.
 
IM using yours, its the only that seems to want to turn on. Im trying to post a screenshot of the Event to see if you can find the error but taking forever to load lol

Flashlight 2 is Unka's and I just turn the trigger and event to one im not using to test.
http://i9.photobucket.com/albums/a91/justmejosh07/Flashlight.jpg[/img]
 
ok, well, first, you aren't allowing a break option in your script. You have the Jump to Label: End but you don't have that label. Put a Label called End as the very last thing on this page. As to why its not working, you need to uncheck the box in your conditional branch that says to control otherwise. The event is getting stuck inside that little else: portion of your conditional branch. So, I think unchecking that box should work.

And I'm sorry about that being off centered. I was just in a hurry to get something down so I could use it to test. If you want one right in the center, then I will make you one if needed. Also, if you want this to be turned on by a button, let me know and I'll get that too you as well.

Good Luck!
~xgamexfreakx
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top