Mother 3's Rolling Meters.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Mother 3's Rolling Meters.

Post by grump »

JustFedor wrote: Tue Sep 12, 2017 3:24 pm So... Anyone have an idea?
Sure, dude. There's a working idea with example code posted in this thread that includes pretty much everything you need, and also descriptions of an alternative implementation with quads. You should now try to adapt one of those ideas, and come back when you have more questions.
JustFedor
Prole
Posts: 7
Joined: Mon Sep 11, 2017 5:45 pm

Re: Mother 3's Rolling Meters.

Post by JustFedor »

grump wrote: Tue Sep 12, 2017 3:55 pm
JustFedor wrote: Tue Sep 12, 2017 3:24 pm So... Anyone have an idea?
Sure, dude. There's a working idea with example code posted in this thread that includes pretty much everything you need, and also descriptions of an alternative implementation with quads. You should now try to adapt one of those ideas, and come back when you have more questions.
I already wrote that I tried to create this thing for about four days. I tried several ideas, and upper one i tried too.
I would not come here if I was not in despair.

Code: Select all

function love.load()
	love.event.quit()
end
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Mother 3's Rolling Meters.

Post by grump »

But... there is a working solution right there, with a description of the basic concept too. What do you expect should happen now?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Mother 3's Rolling Meters.

Post by zorg »

We're not gonna code the thing for you.

Edit: Lol entitlement.
Last edited by zorg on Tue Sep 12, 2017 6:51 pm, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
JustFedor
Prole
Posts: 7
Joined: Mon Sep 11, 2017 5:45 pm

Re: Mother 3's Rolling Meters.

Post by JustFedor »

Sure thanks for help.

(Sarcasm)

Code: Select all

function love.load()
	love.event.quit()
end
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Mother 3's Rolling Meters.

Post by Sir_Silver »

If you still need help, can you ask another question? I looked at grump's code and it seems to be what you wanted (a way to simulate the rolling numbers from the game you mentioned)

Have you tried to implement the code that was given to you? Was it not what you were asking for in the first place? What problems are you having that we could attempt to help you troubleshoot?

I notice you posted
The most hardest part in my opinion is actually getting these digits work by turn.
For counter wheel I use ImageFont and canvas.
But that isn't really a question

Edit: Wow, so you're leaving the forums because no one understands/has an answer for the questions you didn't ask. If you happen to return to this forum, even if it's just to lurk, this is for you OP http://www.catb.org/esr/faqs/smart-questions.html#code
Last edited by Sir_Silver on Tue Sep 12, 2017 8:42 pm, edited 1 time in total.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Mother 3's Rolling Meters.

Post by raidho36 »

In a DIY rainmeter skin I've implemented rolling meter by having a vertical sprite with all the digits on it. It would be used as a texture for a "quad" and the texture coordinate would shift depending on the value of that digit. You could I guess make a bunch of sprites for every possible roller position, like from 0 to 9 and a few places in between each digit. I also made a bunch of sprites with vertical blur applied, so that the rollers could spin fast and it would look fast rather than jittery, which sprite would be used was selected based on digit rolling speed.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Mother 3's Rolling Meters.

Post by grump »

It's kind of funny, but I could swear there was an additional topical response here that just got deleted without notice.
JustFedor
Prole
Posts: 7
Joined: Mon Sep 11, 2017 5:45 pm

Re: Mother 3's Rolling Meters.

Post by JustFedor »

Okay, I just came to say that I just finally created that thing.
Thanks to raidho36 for good explanation, and understanding.

grump, your solution was useless.

So, if anyone needs, here's the code.

Code: Select all

meter = {}
meter.__index = meter

function meter:new(font, cells, init_value, speed)
	local o = {}
	o.font = font or love.graphics.newFont(32)
	o.width = o.font:getWidth'0'
	o.height = o.font:getHeight()
	o.cells = cells
	o.value = init_value or 0
 	 o.actualValue = o.value
 	 o.speed = speed or 7
	o.cell = {}
	o.canvas = love.graphics.newCanvas(o.width, o.height * 11)
 	 o.canvass = love.graphics.newCanvas(o.width*o.cells*2, o.height)
	love.graphics.setCanvas(o.canvas)
	local oldf = love.graphics.getFont()
	love.graphics.setFont(o.font)
	for i = 0, 10 do
		love.graphics.print(i%10, 0, i * o.height)
	end
	love.graphics.setFont(oldf)
	love.graphics.setCanvas()
	for i = 1, cells do
		o.cell[i] = {value = o.value, shift = o.value*o.height, setted = false}
	end
	return setmetatable(o, self)
end

function meter:__add(v)
	self.value = self.value + v
	return self
end

function meter:__sub(v)
	self.value = self.value - v
	return self
end
function meter:set(v)
  self.value = v
  return self
end

function meter:update(dt)
  if self.actualValue < self.value then
    self.actualValue = self.actualValue + self.speed * dt
    if self.actualValue >= self.value then self.actualValue = self.value end
  elseif self.actualValue > self.value then
    self.actualValue = self.actualValue - self.speed * dt
    if self.actualValue <= self.value then self.actualValue = self.value end
  end
	for i, v in ipairs(self.cell) do
		local val = self.actualValue/(10^(self.cells - i))
		val = math.floor(val)
		val = val * self.height
    if v.setted == false then
      v.shift = val
      v.setted = true
    end
		if val > v.shift then 
      v.shift = v.shift + self.speed * self.height * dt 
      if v.shift > val then v.shift = val end
    elseif val < v.shift then
       v.shift = v.shift - self.speed * self.height * dt 
      if v.shift < val then v.shift = val end
    end
	end
  love.graphics.setCanvas(self.canvass)
  love.graphics.clear()
  for i, v in ipairs(self.cell) do
		love.graphics.draw(self.canvas, (i-1) * (self.width + 1), -( v.shift % (10 * self.height)))
	end
  love.graphics.setCanvas()
end

function meter:draw(x, y)
	love.graphics.draw(self.canvass, x, y)
end

This code is dirty, but it works.

Code: Select all

function love.load()
	love.event.quit()
end
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Mother 3's Rolling Meters.

Post by zorg »

I mean, there's always more than one way of accomplishing things.
With or without canvases.
With or without scissors.
With print statements, text objects, or sprite atlases; with or without quads.

But hey, at least you got it working...even if it seems highly inefficient.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 3 guests