How do make the player attachment to a layer?

Description: Official subforum for LunaLua - an extension framework for SMBX Engine Version 1.3 (which a core of SMBX 2.0). Share your creations that require the use of LunaLUA. You may also share info/tutorials on how to use LunaLUA.
Moderator: Moderators

Lx Xzit M
Topic author, Moderator
Moderator
Lx Xzit M
Topic author, Moderator
Moderator
Reputation: 137
Posts: 430
Joined: 9 Nov 2015
Website

Post #1by Lx Xzit » 14 Dec 2015, 22:10

Hi, I'm trying to make a dark cave like NSMBwii but I don't get make the correct code.
I would like that when the player enter into the second section, appear a layer to sticks to him (I will use a png image called "Darklight" in format png). Can someone please help me with the code? Thanks!
VISIT MY YOUTUBE CHANNEL! LX XZIT

Wohlstand M
Lead Developer
Lead Developer
Avatar
Wohlstand M
Lead Developer
Lead Developer
Age: 25
Reputation: 320
Posts: 1297
Joined: 15 Feb 2014
Location: Moscow, Russia
Website Skype YouTube

Post #2by Wohlstand » 14 Dec 2015, 23:15

You don't need to place specific object to make that, you just can make a loop with rendering of your texture at player's center by formula:

texture.x = player.x+(player.w/2) - (texture.w/2)

texture.y = player.y+(player.h/2) - (texture.h/2)

or add/subtract some number if you wish offsetted render or modify -1 or +1 dependent to actual direction if need, etc.

I.e.:

Code: Select all

local texture = Graphics.loadImage("darklight.png")
local player = Player(1)

function onLoop()
     local x = player.x+(player.width/2) - (texture.width/2)
     local y = player.y+(player.height/2) - (texture.height/2)
     Graphics.drawImage(texture, x, y)
end

Lx Xzit M
Topic author, Moderator
Moderator
Lx Xzit M
Topic author, Moderator
Moderator
Reputation: 137
Posts: 430
Joined: 9 Nov 2015
Website

Post #3by Lx Xzit » 15 Dec 2015, 20:27

Again, thank you a bunch! The formula and the code will be very helpful for me.
However I got this error, what I can do?
Spoiler
Image
VISIT MY YOUTUBE CHANNEL! LX XZIT

Lotus006
Nice citizen
Nice citizen
Lotus006
Nice citizen
Nice citizen
Reputation: 1
Posts: 15
Joined: 6 Oct 2015

Post #4by Lotus006 » 17 Dec 2015, 16:38

DarkMecha wrote:Again, thank you a bunch! The formula and the code will be very helpful for me.
However I got this error, what I can do?
Spoiler
Image

Are you sure to have the texture in your folder api ?
and is also your resource is right redirectered ? like this

"syntax"

Code: Select all

local resPath = getSMBXPath() .. "\\LuaScriptsLib\\(your folder api)"


"example"

Code: Select all

local resPath = getSMBXPath() .. "\\LuaScriptsLib\\"dark_api"


Code: Select all

local darklight = Graphics.loadImage(resPath .. "\\darklight.png"); -- Stuff


Also before test just to verify if is not a error on this

Code: Select all

local player = Player(1)

replace by :

Code: Select all

local player = Player1


Return to “LunaLua - Extension Framework”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest