I develop my project using Corona SDK and creating successfully a "virtual moving camera".
The problem I have is about the parameter : ParallaxRatio() It seems it doesn't work, because my camera move the object in the same "speed". I would like the mountain & mountain2 move faster than the bkg_1.
Here is my code:
local perspective = require("perspective")
local camera = perspective.createView()
camera:add(hero,1,true)
camera:add(grass,2,false)
camera:add(mountain,3,false)
camera:add(mountain2,3,false)
camera:layer(3).parallaxRatio=0.5
camera:add(bkg_1,4,false)
camera:layer(4).parallaxRatio=0.2
camera:add(bg,5,false)
Just create a separate function to move the mountains along the x axis.
local function moveMountain(event)
mountain.x = mountain.x - 1.5
if mountain.x <removePoint then
mountain.x = player.x +950
end
end
Runtime:addEventListener("enterFrame",mountain)
Cloud_1.enterFrame = moveMountain
Related
So I have been coding a nextbot in Gmod for a while now and have found a bug that causes Gmod to crash every time the function is run. here is the function:
function ENT:RecomputeTargetPath(path_target)
if self.testmode then
PrintMessage(HUD_PRINTTALK, 'recomputing target path')
end
self.path = Path("Chase")
if (CurTime() - self.LastPathingInfraction < 5) then
return
end
local targetPos = path_target:GetPos()
-- Run toward the position below the ENTity we're targetting, since we can't fly.
trace.start = targetPos
trace.filter = self:GetEnemy()
local tr = util.TraceEntity(trace, self:GetEnemy())
-- Of course, we sure that there IS a "below the target."
if (tr.Hit and util.IsInWorld(tr.HitPos)) then
targetPos = tr.HitPos
end
local rTime = SysTime()
self.path:Compute(self, targetPos)
if (SysTime() - rTime > 0.005) then
self.LastPathingInfraction = CurTime()
end
end
When this function is run, it recomputes the target path for the nextbot to make it move differently.
It's used in the context of an if that looks like this or something very close:
if (CurTime() - self.LastPathRecompute > 0.1) then
self.LastPathRecompute = CurTime()
self:RecomputeTargetPath(self:GetEnemy():GetPos())
end
As far as I know, all variables in the if are called before each.
As far as I know, all variables in the if are called before each.
I tried recalling them but that didn't work at all... I don't know what is happening.
Also, side note, the function gets called multiple times per second based on the player's movement.
I've also added debug prints to every line of the code to see where the issue was and the bug fixed itself when I added them but when I removed them the bug came back...
Any help?
I have this script that duplicates an object and teleports it to the player when the GUI button is pressed (You can think of GMod to make things easier). It is stored in a LocalScript inside the button and when you press it, but it's only visible for the player that clicked the button.
I'm not exactly sure how I would solve the problem or what the problem is, but I think it's because it's all stored into a LocalScript. I'm new to Lua and Roblox game development and I didn't really take any lessons on it, I'm just working from my memory and experience. Any and all suggestions are greatly appreciated. Also, if I need to give more information, please ask and I will provide it.
My script:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local rag = game.Lighting.ragdolls_presets["Wood Crate"]:Clone()
local X = player.Character.UpperTorso.Position.X
local Y = player.Character.UpperTorso.Position.Y + 10
local Z = player.Character.UpperTorso.Position.Z
rag.Parent = game.Workspace.ragdolls
local children = rag:GetChildren()
for i = 1, #children do
local child = children[i]
child.Position = Vector3.new(X,Y,Z)
end
end)
Thank you in advance!
When you clone something in a LocalScript, it only clones on the client side. Changes done on the client side never gets replicated to the server side, however all changes done on the server side would get replicated to all clients, which are the players.
So to fix this you'd need to use RemoteEvents, which is a way for the client to tell the server to do something.
So instead of doing this in a LocalScript
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local rag = game.Lighting.ragdolls_presets["Wood Crate"]:Clone()
local X = player.Character.UpperTorso.Position.X
local Y = player.Character.UpperTorso.Position.Y + 10
local Z = player.Character.UpperTorso.Position.Z
rag.Parent = game.Workspace.ragdolls
local children = rag:GetChildren()
for i = 1, #children do
local child = children[i]
child.Position = Vector3.new(X,Y,Z)
end
end)
Put a new RemoteEvent in game.Replicated Storage, then:
This should be the LocalScript
local Event = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
Event:Fire()
end)
And this should be the ServerScript (or Script for short)
local Event = game.ReplicatedStorage.RemoteEvent
Event.OnServerEvent:Connect(function(player)
local rag = game.Lighting.ragdolls_presets["Wood Crate"]:Clone()
local X = player.Character.UpperTorso.Position.X
local Y = player.Character.UpperTorso.Position.Y + 10
local Z = player.Character.UpperTorso.Position.Z
rag.Parent = game.Workspace.ragdolls
local children = rag:GetChildren()
for i = 1, #children do
local child = children[i]
child.Position = Vector3.new(X,Y,Z)
end
end)
Also, it is very important to do server-side validation when using RemoteEvents, for example: instead of checking whether a player has enough money to spawn something in a LocalScript before the RemoteEvent is fired, it should be done in both LocalScript and the ServerScript. The cause for this is that players can change anything in their client side, so information from the client can NOT be trusted. Optionally you can also have time-outs in each side because, lets say a player has millions of money, he can keep executing the RemoteEvent hundreds of times in under a minute which can crash the server or cause extreme lag. So a 3 second - 1 minute time out is sometimes necessary
More information about Roblox's Client-Server Model: https://create.roblox.com/docs/scripting/networking/client-server-model
More information about Roblox RemoteEvents: https://create.roblox.com/docs/reference/engine/classes/RemoteEvent
I'm building a Love2D project and using LoveFrames as the UI library. I'm having trouble hooking components into changes that happen in love.update closure. For example, if a count variable is updated in love.update, I want the updated count to show in a frame's title.
So below are snippets that show what I'm trying to achieve.
main.lua
local loveframes = require("libraries.loveframes")
local Home = require("screens.Home")
availablePlayersCount = 0
function love.load()
Home(loveframes)
end
Home.lua
function HomeScreen(loveframes)
local frame = loveframes.Create("frame")
frame:SetName(availablePlayersCount) -- This should update with respect to updates made in love.update
frame:SetState("homestate")
loveframes.SetState("homestate")
end
I'm currently using giderous studio to make a tower defense game. However the code doesn't run as expected.
I made a function that make the monster in the game move according to the route settled in a JSON file. The move process go well EXCEPT the first monster being spawned firet, I have absolutely no ideas why the monster stop on its way. (As shown as diagram)
The following is my code:
level.lua:
level = Core.class(Sprite)
function level:init(levelId)
local level = dataSaver.load("level");
--load attributes
self.lives=level[tostring(levelId)]["lives"];
self.route=level[tostring(levelId)]["route"];
self.round=level[tostring(levelId)]["rounds"];
self.towersAllowed=level[tostring(levelId)]["towers"];
--some varibles
self.currentRound=1;
self.monsterList={};
end
function level:spawnMonster()
local monsterType=self.round[1]["type"];
local spawnNumber=self.round[1]["number"];
--set timer for spawn
local timer = Timer.new(self.round[1]["spawnInterval"],0);--spawnNumber);
timer:start();
--spawn
timer:addEventListener(Event.TIMER,function()
local spawnedMonster = monster.new(monsterType);
spawnedMonster.instance:setPosition(self.route[1]["x"],self.route[1]["y"]);
self:moveMonster(spawnedMonster);
end);
--after spawn finished, wait for next round.
timer:addEventListener(Event.TIMER_COMPLETE,function()
local nextRound = Timer.new(self.round[1]["timeUntilNextRound"],1);
nextRound:start();
nextRound:addEventListener(Event.TIMER_COMPLETE,function()
print("nextRound");
end);
end);
end
function level:moveMonster(monsterToMove)
if (monsterToMove.currentDes<=#self.route) then
monsterToMove:move(self.route[monsterToMove.currentDes]["x"],self.route[monsterToMove.currentDes]["y"]);
monsterToMove:addEventListener("monsterMoveDone",function()
monsterToMove.currentDes=monsterToMove.currentDes+1;
self:moveMonster(monsterToMove);
end);
end
end
monster.lua:
monster = Core.class(Sprite)
function monster:init(type)
local monstersList = dataSaver.load("monster");
self.instance = quickImage(monstersList[type]["image"], _W/2, _H/2,monstersList[type]["width"], monstersList[type]["height"]);
self.speed=monstersList[type]["speed"];
self.health=monstersList[type]["health"];
stage:addChild(self.instance);
---some varibles...
self.currentDes=2
end
function monster:move(desX,desY)
local time=getDistance(math.abs(self.instance:getX()-desX),math.abs(self.instance:getY()-desY))/self.speed
local mc = MovieClip.new{
{1, time, self.instance, {x = {self.instance:getX(), desX, "linear"}}},
{1, time, self.instance, {y = {self.instance:getY(), desY, "linear"}}},
}
mc:addEventListener(Event.COMPLETE,function()
self:dispatchEvent(Event.new("monsterMoveDone"))
end);
end
from the code, quickImage(); is just a little function for making image sprite
Any ideas, I thought maybe i make the memory allocating wrong.
Special Note. I run Gideros Studio under OpenSUSE 12.2 with Wine, but i don't think its a matter because all stuff go well.
local Flipbook = `enter code here`require 'flipbook'
local myFirstFlipbook = Flipbook:newFlipbook("background_back.png", "mainshadow.png", "newshadow.png", "curlshadow.png" )
myFirstFlipbook:addPage( "backgroundA.png" )
myFirstFlipbook:addPage( "backgroundB.png" )
myFirstFlipbook:addPage( "backgroundC.png" )
Used the above code to implement the page curling effect
I want to add a sprite in one of the pages such that the sprite also curls as the page , and I am facing lots of issues implementing it
If anyone could guide me through this... would be a great help.