local cloud = ActiveAnimations["cloud"]
cloud:to(10000, { AnimationCurrentPosition = {x = -1000, y = cloud.AnimationCurrentPosition.y} }, easeLinearInOut, true, false)
Thank you, I got another question. I'd need a way to scale an object based on a variable value, how can I achieve it? Basically it for an health barA'llo,You should create the cloud as an animation as it's much easier to move than objects. Object movement is offset based whereas animations can be moved to absolute positions.There are also multiple methods for moving objects & animations, but the simplest method is the to() tweening function as you can specify the time it takes to get from the starting position to the target position as well as specify easing & make it loop &/or loop forwards then backwards (pendulum) when it gets to the target position.Here's a quick example of how you could have a cloud move from a starting position, to an end position, then loop from the start again...local cloud = ActiveAnimations["cloud"] cloud:to(10000, { AnimationCurrentPosition = {x = -1000, y = cloud.AnimationCurrentPosition.y} }, easeLinearInOut, true, false)
In the example above we are moving a cloud from the starting position to -1000 pixels over 10000ms (10 seconds) with linear easing (default easing) & once it reaches the target position it will loop back to the starting position & make its way across the scene again.Other alternatives are to increment the position of the animation via an execute a script action part that you create inside of the animation frame. Another method would be to use a mainLoop event handler & increment/decrement the position via that.Quick note #1: you need to make sure you set the animation to loop infinitely & also the animation should be assigned as the default animation of the scene object you created the animation under.Quick note #2: if you want to get a bit more creative with sliding objects around scenes, then you should look into math.random or the random value action part as it will allow you to create more dynamic content. For example, you could change the target position or the amount of time in which it should take to get from the starting position to the target position.
graphics.addDrawFunc("draw()", 0)
function draw()
graphics.drawBox(200, 200, 300, 40, 0x0000ff, 1)
end
graphics.addDrawFunc("draw()", 1)
function draw()
graphics.drawBox(x, y, w, h, color, alpha)
end
</div>
if Values["MC_health"].Int == 100
then
graphics.addDrawFunc("draw()", 0)
function draw()
graphics.drawBox(200, 200, 300, 40, 0x0000ff, 1)
else
if Values["MC_health"].Int == 50
then
graphics.addDrawFunc("draw()", 0)
function draw()
graphics.drawBox(200, 200, 150, 40, 0x0000ff, 1)
end end
if Values["MC_health"].Int > 50 then
graphics.addDrawFunc("draw()", 0)
function draw()
graphics.drawBox(200, 200, 300, 40, 0x0000ff, 1)
end
elseif Values["MC_health"].Int > 0 and Values["MC_health"].Int <= 50 then
graphics.addDrawFunc("draw()", 0)
function draw()
graphics.drawBox(200, 200, 150, 40, 0x0000ff, 1)
end
end
Perfect it works.captcha code? I don't have one on here. I think there may be one for members with less than x posts as a anti-spam preventative, but sure, I also wish the captcha would bugger off too - 2 step verification as well & anti-cheat in games.No, something more like this...if Values["MC_health"].Int > 50 then graphics.addDrawFunc("draw()", 0) function draw() graphics.drawBox(200, 200, 300, 40, 0x0000ff, 1) end elseif Values["MC_health"].Int > 0 and Values["MC_health"].Int <= 50 then graphics.addDrawFunc("draw()", 0) function draw() graphics.drawBox(200, 200, 150, 40, 0x0000ff, 1) end end
but that's not a very efficient solution. It would be better to use some math to calculate the health bar width based on the value.
I´m not sure about this but wouldn´t this register the draw function again and again? Since the draw function is called every frame this would get very expensive soon
local health
graphics.addDrawFunc("draw()", 0)
function drawHealthBar()
health = (Values["MC_health"].Int / 100) * 300
-- + --
function draw() graphics.drawBox(200, 200, health, 40, 0x0000ff, 1) end
end
registerEventHandler("mainLoop", "drawHealthBar")