draw sprite outside draw events?

D

dugtrioramen

Guest
I just saw the new forums and its a good thing because for the past few weeks i've been having trouble with Draw_sprite functions.
There are many people online saying only draw_sprite functions should be put in draw events but are you able to use draw_sprite(thing,num,x,y) in a step event or an alarm or something.
Because every time i use any draw_sprite functions outside a draw event, it never shows anything. But then when i put it in the draw event it works.
And the reason draw events are a problem is because they apparently dont update every step. Which is why i need to do it in a step event.
 

FrostyCat

Redemption Seeker
That's why skilled users tell you that drawing functions belong only in Draw events: they have no visible effect in any other event.

Also, Draw events re-run every step, I have no idea how you observed otherwise. This behaviour is clearly documented in the Manual. If you have issues with residual graphical junk and there are areas in the room not covered by a background, make sure the background colour is turned on.
 
D

dugtrioramen

Guest
1) in the wrong section, don't know how to change it, can a moderator move it or something
and

2)@FrostyCat i did read this from here
Draw: The standard Draw Event should be sufficient for most of your needs. The Draw Event enables you to place code or Actions for an Object, and those Actions and code override the default draw, which would be the assigned Sprite.

This is useful, for example, if you want to replace the assigned Sprite with text to display a message. This Event is called once per View, while the other Draw Events are drawn each step of the game.

and i did try this to ceck if it was true.
draw_sprite(spr_thing,variableSubImg,x,y)
in a step event i had it increment variableSubImg, tried with begin step as well.
The picture stayed static
 
A

Aura

Guest
What you have read from is not the Manual.

http://docs.yoyogames.com/source/dadiospice/000_using gamemaker/events/draw event.html

All of the Draw events are run every step per se. But as @FrostyCat said, you are supposed to draw things in a Draw event. And I don't see why this won't work:

Create:
Code:
img = 0;
num = sprite_get_number(spr_thing);
Step:
Code:
img += 1;
if (img >= num) {
   img = 0;
}
Draw:
Code:
draw_sprite(spr_thing, img, x, y);
...unless you have misplaced actions into wrong events.
 
I read that page you linked to. Personally, it sounds like whoever wrote that article doesn't actually know what they are talking about, and also worded things terribly. I wouldn't put much stock in non-official sources of information. It has been stated by the developers that drawing should be done in the draw events only, and really, any situation where you think it needs to be done elsewhere can and should most definitely be done in the draw event. Long story short: Just do all your drawing in the draw events and be done with it.
 

TheouAegis

Member
You can draw to a surface during any event and then draw the surface during the draw event. If you can limit drawing to surfaces during the draw event though, you should try to do so.

And as far as what you quoted and underlined, it doesn't say the Draw Event is run less frequently, it says it is run more frequently. For every view in the room, the draw event is handled. So if you have 3 views visible and you put draw_sprite(hpbar, 0, view_xview[0], view_yview[0]) to draw a health bar at the top of view 0, that code will still be run for views 1 and 2, but you probably won't see anything.
 
D

dugtrioramen

Guest
Well that's good to know everybody, i was just cautious about checking for cases in draw events since the actual manual (i've learned my lesson) stated it was very intensive.
Oh and regarding what @Aura said, i messed up in the step event because i reset the sub image to 0 at the start so yeah
:D
 
Top