how to fire bullet after touching the sprite

Greetings gunnervikas and welcome to the new yoyo forum.

your question is a bit vague because i do not understand what is touching what but ill presume that the bullets only go in one direction and the bars are buttons you click.

if thats the case then take all the colours for the bullets and put it in one sprite image, then make anothe sprite for the bars and make sure the order of the bars is the same as the order of the bullets.

then when you click on a button have it say

Code:
bullet = instance_create(self.x,self.y,obj_bullet) //this is presuming you are having the button create it
bullet.image_index = image_index //this will match the bullet colour to the bar colour
and you are done, so long ass the bullets and bars are in the same order in the sprites then you will have bullets that match the bars that shot them.

hope this helped, good luck.
 
S

Snail Man

Guest
The easiest way is just to have 3 bullet objects, one for each color, and 3 collision events, one for each object. A more nuanced approach would be to use image_index and have the bullet/object sprites have 3 sub images with one color in each. Then you can just fire the bullet of the same us image as the object.

Edit: ninja'd
 

chorrus

Member
Hi,

If you don't need multitouch and they are different objects, use left_pressed event. Inside left pressed event use instance_create(x,y,obj_bullet(or however you named it)).

Anyway, it's hard to answer this question without more details, let us know exactly what you need and the method you are currently using. There are many roads to Rome, we need to know the one you need :)
 
D

Darth Raven

Guest
You mean, everytime you press those buttons it will shoot bullets? That is simple.
We can make it in two possible ways, one using the Drag and Drop GameMaker or code.

Drag and drop:
At the object related to the sprite of the button use:
Event: Left button Pressed
- Create instance (x and y are the coordinates where it is created ; the object should be the sprite you want)

At the object bullet:
Outside of room: Instance destroy ( so it doesnt make your pc slow for running bullets that are not even on the screen ).
Create event: - Vertical speed (vspeed) (Positive numbers so it goes down).
If you want to use code:
Button object:
Step event:

if mouse_check_button_pressed(mb_left)
{
instance_create(x,y,bulletobject)
}

At the object bullet:
Create event:

vspeed = -2

if y= room_height
{
instance_destroy()
}
 
Top