Thread Tools Display Modes
11-07-14, 10:11 AM   #1
Spydyr
A Defias Bandit
Join Date: Nov 2014
Posts: 2
Goofing off -

Hello,

I am probably missing something really simple here, but what I am trying to do is make a whole bunch of "pixels" that I can set colors of individually. You may ask why, when you can load an image etc ... the real reason is simple, using this to learn how things function with lua.

So with out further ado ... my horrible code.

(I expected this to make a square of red, but it just makes a line)


Sprite = {}
local Sprite = {}
Sprite.frame = CreateFrame("Frame",nil,UIParent)
Sprite.frame:SetFrameStrata("BACKGROUND")
Sprite.frame:SetWidth(100)
Sprite.frame:SetHeight(50)

local spriteSet = {}
Sprite.spriteSet = spriteSet
spriteSet.count = 0
function spriteSet:setColor(i,r,g,b,a)
spriteSet[i]:SetTexture(r,g,b,a)
spriteSet[i].r = r
spriteSet[i].g = g
spriteSet[i].b = b
spriteSet[i].a = a
end
function spriteSet:setIndividualColor(pos,bValue)
local p = math.floor(pos/3)
local rgb ={}
rgb[0] = spriteSet[p].r
rgb[1] = spriteSet[p].g
rgb[2] = spriteSet[p].b
rgb[mod(pos,3)] = bValue/256
spriteSet[p].r = rgb[0]
spriteSet[p].g = rgb[1]
spriteSet[p].b = rgb[2]
spriteSet[p].a = 1
spriteSet[p]:SetTexture(spriteSet[p].r,spriteSet[p].g,spriteSet[p].b,spriteSet[p].a)
end
function spriteSet:clear()
local l = 0
while l < spriteSet.count do

spriteSet[l].r = 0
spriteSet[l].g = 0
spriteSet[l].b = 0
spriteSet[l].a = 0
spriteSet[l]:SetTexture(0,0,0,0)
l = l + 1
end
end





spriteSet.maxColumns = 50
spriteSet.maxRows = 25
local col_, row_
for col_ = 0, 100,2 do
for row_ = 0, 50,2 do

local t = Sprite.frame:CreateTexture(nil,"BACKGROUND")

t.r = 1
t.g = 0
t.b = 0
t.a = 1
t:SetTexture(t.r,t.g,t.b,t.a)

print(col_,row_)-- Debug TBD:remove
t:SetPoint("TOPLEFT", col_,row_)
t:SetSize(2, 2)
spriteSet[spriteSet.count] = t
spriteSet.count = spriteSet.count + 1
end
end

print(spriteSet.count) -- Debug TBD:remove

Sprite.frame:SetPoint("TOPLEFT",0,0)
Sprite.frame:Show()
  Reply With Quote
11-07-14, 10:40 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Hi Spydyr,

I do agree with you - you code is really horrible.
A first step would be to use the LUA tag when posting lua code.

You do create a 50x25 block of textures each having a size of 2x2. That's an overall size of 100x50 pixels. A "square" should be impossible.

Besides that there are so many potential problems within your code that I probably should ask in a first step if you have lua errors enabled within the wow client and if there are errors.
  Reply With Quote
11-07-14, 10:42 AM   #3
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Didn't run the code, but first, you'd better test these things in the middle of you screen, thus you see where they go. Second, apparently, you dun have a line, you get red rectangle, but columns in your array grow up, because row_ is a positive number and it's used as Y coordinate in SetPoint function, use -row_ instead
Lua Code:
  1. t:SetPoint("TOPLEFT", col_, -row_)
P.S. That's helluva messy
__________________

Last edited by lightspark : 11-07-14 at 10:49 AM.
  Reply With Quote
11-07-14, 10:51 AM   #4
Spydyr
A Defias Bandit
Join Date: Nov 2014
Posts: 2
Red face

because row_ is a positive number and it's used as Y coordinate in SetPoint function, use -row_ instead
Yeah, this was what my problem was. I was thinking of coords with y going down on the screen as y goes up. Woops.

Besides that there are so many potential problems within your code that I probably should ask in a first step if you have lua errors enabled within the wow client and if there are errors.
Nope, I do have lua errors enabled, like I said I am just goofing off learning how wow/lua interacts.

I got it to work by changing the position of the initial frame ... then saw what I had done and went ... god I hope I can delete that post before anyone sees it heh.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Goofing off -


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off