Quickies

Sometimes viewers on YouTube ask a question that requires a little more space than provided in the reply box, so here are some coding answers to some questions.

Screen Shake Modified To Work With View Following Player
in my original code I set view[0] to be shifted around by the value of the calculated variable ‘xp’.   If you have a view following the player then you have to set the position of the view so that the player will be centered in the view and then apply this shift of ‘xp’.   You could modify the line

view_xview[0] = xp      and change it to
view_xview[0] = oPlayer.x – view_wview[0]/2.0 + xp

Do similar to y axis but use   view-hview[0]/2.0 + yp.  Assuming player object is called oPlayer.  Note this will only work when the player object exists so you should do a quick check before to make sure it does…

Clipped Code from Energy Bar Smooth Changing How-To Video

///initGlobal()

global.energy=75
global.energyTarget=75
global.energySlideRate=0.10
///drawEnergyBar()
var xp=300;
var yp=50;
var width=500;
var height=50;
var border=5;

//what percentage of bar should be drawn?
var perc=global.energy/100.0 // perc=.75
//CENTERED ENERGY BAR
//outer border of energy bar #1
draw_roundrect(xp-width/2.0, yp, xp+width/2.0, yp+height, false)
draw_set_color(c_white)
draw_set_alpha(0.6)
draw_rectangle(xp-width/2.0+border, yp+border, xp+width/2.0 – border, yp+height-border, false)

//the changing green energy bar #1
draw_set_alpha(0.5)
draw_set_color(c_green)
draw_rectangle(xp-perc*(width/2.0-border), yp+border, xp+perc*(width/2.0-border), yp+height-border, false)
draw_set_alpha(1.0)
//LEFT JUSTIFIED ENERGY BAR
//outer border of energy bar #2
xp = 50
yp = 150
draw_roundrect(xp, yp, xp+width, yp+height, false)
draw_set_color(c_white)
draw_set_alpha(0.6)
draw_rectangle(xp+border, yp+border, xp+width-border, yp+height-border, false)

//the changing green energy bar #2
draw_set_alpha(0.5)
draw_set_color(c_green)
draw_rectangle(xp+border, yp+border, xp+border+perc*(width-2*border), yp+height-border, false)
draw_set_alpha(1.0)
//draw energy and energytarget
draw_set_color(c_green)
draw_set_alpha(0.6)
draw_text(230, 112, “Energy: ” + string(global.energy) )
draw_text(230, 127, “EnergyTarget: ” + string(global.energy) )
///updateEnergy()

var diff = global.energyTarget – global.energy
if diff=0
exit

var change = diff*global.energySlideRate

global.energy += change
if abs(diff) < .25
global.energy = global.energyTarget

Code, Compile, Smile