SOLVED sync draw event with step event

jonjons

Member
hello
anyone knows whats the best way to sync an instance_create in the step event with the draw event ?
I have the player sprites being drawn in the draw event, and an object weapon being created in the step witch follows the player.

the lag can be notice with the game at 10fps... I think it has 1 step of lag
 

curato

Member
Best thing to do would be to set a variable in the step that the player equipped the sword then in the draw even if it is set then draw the sword at the same time you are drawing the player then everything should be perfectly in sync.
 

Mr Magnus

Viking King
Question: Why is your game running ten frames per second? That's starting to approach slideshow levels of refresh rate.
 

jonjons

Member
thanks for the replies
I could set the object sword sprite in the draw event... I tough about it, but then ill loose the depth variable. In some animations i need to put it behind the player others in front.
It would require something like a boolean to draw it before or after the player sprite. And the code gets very confusing, iam trying to keep the levels of bureaucracy at a minimum... I already have too much bureaucracy in my code, if i keep raising the levels of bureaucracy, it becames very hard to work with it... Might has well put it in a museum when its finished and leave it has it is... Its suitable for people to look at it, but its not suitable has a working app, with all the bureaucracy in it people would need to read an encyclopedia to know how it works.
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
[PROBLEM]
from what I understood you:
1) have a player object
2) have a weapon object
3) want to set the weapons position to something relative to the players

[SOLUTION]
you can either use:
1) the weapon [End Step Event] to set its position relative to the player
2) the player's [End Step Event] to set the weapon's position to the correct coordinates
depending one where you want the logic to be. But the key here is to use the [End Step Event]
 
Last edited:
just put the code you use for the gun
you can either use:
1) the weapon [End Step Event] to set its position relative to the player
2) the player's [End Step Event] to set the weapon's position to the correct coordinates
depending one when you want the logic to be. But the key here is to use the [End Step Event]
use the end step event for the weapon like he said.
 

jonjons

Member
The Begin Step is works fine, but breaks the player facing direction
The end Step puts the obj weapon 1 step ahead, but the facing direction is correct

BEGIN STEP

END STEP

//---//-----
...................
 

xDGameStudios

GameMaker Staff
GameMaker Dev.
Take this two notes into consideration:
1) you need to set player position and facing on the step event then use step end to do the same for the weapon!
2) your draw event should not change position/facing just drawing.

Can you provide the code you are using to set the weapons position? on the [STEP END EVENT]

Sorry but I don't actually understand what I'm supposed to see in the videos.
 
Real simple solution, here.
1- Have an EMPTY draw event in the weapon object.
2- Calculate angle and position of gun in the PLAYER instance step event, AFTER you updated the Player's position. This could include checking for depth as well.
3 - In the PLAYER draw event:
GML:
draw_self();
with(obj_weapon){                    //reverse order as per the desired depth (gun in front or behind the player sprite)
    draw_self();
}
100% guarantee both will be updated on the same frame, as per your calculations.
 
Last edited:

xDGameStudios

GameMaker Staff
GameMaker Dev.
Real simple solution, here.
1- Have an EMPTY draw event in the weapon object.
2- Calculate angle and position of gun in the PLAYER instance step event, AFTER you updated the Player's position
3 - In the PLAYER draw event:
GML:
draw_self();
with(obj_weapon){                    //reverse order as per the desired depth (gun in front or behind the player sprite)
    draw_self();
}
100% guarantee both will be updated on the same frame, as per your calculations.
@jonjons, this would probably be the best solution :)
I was avoiding pushing it myself because you might have your code structured some other way.
but follow this rules:

1) the player owns the weapon so the player should change the weapons position himself.
2) this placement of the weapon must be done AFTER the movement of the player
3) if possible make the player (owner) handle the draw of all owned instances.. (weapons/hats/boots...)
4) if you have multiple obj_weapon on screen in the code suggested by @Slow Fingers you might want to replace obj_weapon with the actual instance of the weapon (the return value of instance_create_*) functions
 

jonjons

Member
thanks
I already have it working, theres no need for extra events.
i had...
1) player moving x and y, gravity
2) player animation
3) facing direction
4) obj weapon coords

//---change it to---//--

1) player moving x and y, gravity
2) facing direction
3) obj weapon coords
4) player animation

now everything is in sync
 
Top