Page 2 of 3

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 3:55 pm
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.

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 4:25 pm
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.

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 4:34 pm
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?

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 4:38 pm
by zorg
We're not gonna code the thing for you.

Edit: Lol entitlement.

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 5:10 pm
by JustFedor
Sure thanks for help.

(Sarcasm)

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 5:28 pm
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

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 7:13 pm
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.

Re: Mother 3's Rolling Meters.

Posted: Tue Sep 12, 2017 9:57 pm
by grump
It's kind of funny, but I could swear there was an additional topical response here that just got deleted without notice.

Re: Mother 3's Rolling Meters.

Posted: Wed Sep 13, 2017 6:41 am
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.

Re: Mother 3's Rolling Meters.

Posted: Wed Sep 13, 2017 7:30 am
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.