Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Extending Gideros - Page 5 — Gideros Forum

Extending Gideros

1235

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited November 2012
    @Scouser, yes there was an idea to provide also setting alpha for shadows, but I encountered a problem discussed in first post, which I did not solve yet:

    Show child behind the parent or not inherit alpha
    Explanation:

    Shadows for TextField is implemented making real textfield act as shadow and it's child as real displayable text, making shadow the parent of real text. This gives two disadvantages, a little more complex to implement, but we handled that, and inability to set alpha transparency to shadow, because real text automatically inherits it.
    So what could be the solution to this: making shadow child of a real text, but make it appear under real text, not on top of it or do not let real text inherit alpha from parent.
    I thought of other possible implementations, as adding shadow as a brother of textfield (setting it before textfield) under same parent, but this raised many unwanted scenarios, where original textfield changes z-index, or parent, which would require a lot of additional code to bypass this scenarios. But I'll hear any ideas you might have
    @moopf thank you for finding, I always seem to forget to put recall on anchoring :D

    BTW I'm working on a game right now, using GiderosCodingEasy so will implement some fixes I found from that and also some additions (mostly to box2d wrapper) ;)

    Hopefully this all will be done on weekend ;)

  • Just a thought on the shadow alpha thing. Could the TextField not be a Sprite object (like a placeholder) with the text & shadow as it's children?
  • Could it not be handled as
    createText( x, y, text, fontName, fontSize, hasShadow )
    this could then create a group with two textFields, one which is the shadow with the relevant alpha and the one on the top the actual textField. While there would be no more direct access to the textField as the returned object is a group. That is where the setText can be overridden on the group to set the text for both the shadow and the text.

    Just another way to deal with it ( creates an extra object that's all, but can offer more flexibility )

    my $ 0.02
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @OZApps: That's what I said, a placeholder (group) to hold the text & shadow objects as it's children.
  • @OZApps: That's what I said, a placeholder (group) to hold the text & shadow objects as it's children.
    Sorry, I was a bit out of sync with the discussion. Yes, that is what you said.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • Yes I had the idea of another container, I can't really remember what was the scenario were this was a very bad case.
    But basically it means that TextField object is not a textfield object any more, but for example sprite called TextField object having two children and all of it's methods should be overriden.

    Well if I won't remember why I didn't go with that in the first place, I will try to re-implement it using grouping element :)
  • moopfmoopf Guru
    edited November 2012
    Hi @ar2rsawseen, I'm just trying out the sprite transforms and I couldn't get the param skewX etc. to be accepted. Have change the Sprite.transform definition to:
    <pre>
    Sprite.transform = {
    	skew=1,
    	skewX=2,
    	skewY=3
    }
    And that seems to have sorted it. It's because you're testing for keys in the set routine, and the way it was by default they were being set as values instead.

    Edit: skews also mess up anchor points as well :)

    Edit Edit: In fact skews are completely messing up positions.

    Edit Edit Edit: There are no getters either for the values you set.
  • :D @moopf thanks, another thing to add to list :)
    Will try to experiment with skewing more ;)
  • One thing that I recollect is the anchor points can be scaled and applied for objects, but when rotating they do not work very well, any thing on that?
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • bowerandybowerandy Guru
    edited November 2012
    Hi @ar2rsawseen, I'm just starting to use GiderosCodingEasy in anger in a project and I've come across this. Around line 652 I have had to modify the TexturePack.new override as follows:
    local function defExt(path, ext)
    	local found, len, remainder = string.find(path, "^(.*)%.[^%.]*$")
    	if found then
    		return path
    	else
    		return path .. "." .. ext
    	end
    end
     
    TexturePack._new = TexturePack.new
     
    function TexturePack.new(...)	
    	local pack
     
    	local arg={...}
    	if type(arg[1]) == "string" then
    		local txt=defExt(arg[1], "txt")
    		local png=defExt(arg[2] or arg[1], "png")
    		pack = TexturePack._new(txt, png)
    	else
    		pack = TexturePack._new(...)
    	end
     
    	return pack
    end
    As I see it there are two issues:

    1) I was getting an error "attempt to index local 'arg' (a nil value)". This may be related to this article on StackOverflow. At any rate, including the line "local arg={...}" seems to fix it.

    2) I think your assumption that if a filename is supplied then it will not have an extension is rather restrictive (certainly it caught my existing code out in a number of places). Hence I have added the defExt() function to only append an extension to the filename(s) if one has not already been supplied. There may be some other situations in GiderosCodingEasy where this may be useful too.

    Let me know if you agree with these fixes.

    best regards
  • ar2rsawseenar2rsawseen Maintainer
    edited November 2012
    Oh my god, I have so much things to do with GiderosCodingEasy and they keep piling up. :)

    But I have a very good excuse. My friend (in attempt to persuade me to buy one) gave me a Kinect to try for couple of weeks. And I couldn't have done any work at home since. :)

    But don't worry, it will be over soon :)

    @bowerandy completely agree, first attempt was a quick and dirty one.
    But don't understand why arg does not work anymore, did Gideros upgrade Lua version or something like that? Will need to apply solution in many places, thanks again @bowerandy ;)
  • @ar2rsawseen, well whatever you do, don't visit this page or we may never see you again:

    http://ipisoft.com/products.php

    best regards
  • :))
    ok I'll wait till I give kinect back ;)
    Which games have you tried on Kinect?
    You have to dance with Dance Central at least once, to PokerFace... ;)

    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • @ar2rsawseen, well whatever you do, don't visit this page or we may never see you again:
    http://ipisoft.com/products.php
    best regards
    That is a great site, specially since from there I got to know of Source Filmmaker from Valve, a free tool for creating 3D models and animations. Maybe once we get 3D capabilities in Gideros, this would be handy.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • Well I don't really like dancing, I mostly play Kinect Sports, Football seems to be my favorite. Also love Fitness. But my wife plays Dance Central a lot. :)
  • bowerandybowerandy Guru
    edited December 2012

    That is a great site, specially since from there I got to know of Source Filmmaker from Valve, a free tool for creating 3D models and animations. Maybe once we get 3D capabilities in Gideros, this would be handy.
    OFFTOPIC: Well, I already have a copy of that motion capture stuff and I've been using it with two Kinects to capture animations. Works quite well, even detecting the motions that would be in "shadow" when just using a single Kinect. Indeed, I have an interesting idea for a game to make use of this when @atilim can get around to implementing Asynchronous Loading of Textures (ahem!!).

    best regards

    Likes: OZApps

    +1 -1 (+1 / -0 )Share on Facebook
  • bowerandybowerandy Guru
    edited December 2012
    @ar2rsawseen, have you finished playing with that Kinect yet?

    I've found a couple more changes that I think are needed in GiderosCodingEasy.

    I'm currently working on a gradient fill for shapes and to do it I need to be able to replay the points that are already recorded inside an existing shape. I see that you currently attempt to keep a record of all the points in the _allPoints array. However, I don't think this is being updated correctly because you don't bump the index. Currently the array is always empty. Here is the change I think is required:
    Shape._moveTo = Shape.moveTo
     
    function Shape:moveTo(x,y)
    	self:_moveTo(x, y)
    	self._lastPoint = { x, y }
    	self._allPoints[#self._allPoints+1] = x
    	self._allPoints[#self._allPoints+1] = y
    	return self
    end
     
    Shape._lineTo = Shape.lineTo
     
    function Shape:lineTo(x,y)
    	self:_lineTo(x, y)
    	self._lastPoint = { x, y }
    	self._allPoints[#self._allPoints+1] = x
    	self._allPoints[#self._allPoints+1] = y
    	return self
    end
    With that done the Shape:drawPoly() function needs to modified to make use of the array that is returned from Shape:getPoints():
    function Shape:drawPoly(points)
    	local drawOp=self.moveTo
    	self:beginPath()
    	for i = 1, #points, 2 do
                  drawOp(self, points[i], points[i+1])
    			  drawOp=self.lineTo
    	end
    	self:closePath()
    	self:endPath()
    	return self
    end
    Note I think there was also a bug in the original implementation because you did a lineTo() the first point. I have modified this to do a moveTo().

    In order to accept this format of point array then Shape:drawRectangle(0 needs modifying:
    function Shape:drawRectangle(width, height)
    	return self:drawPoly({0, 0, width, 0, width, height, 0, height})
    end
    Finally, you are not recording the interpolated points inside Shape:quadraticCurveTo() and Shape:bezierCurveTo() because you go direct to the original _lineTo methods. Hence I think these should be:
    function Shape:quadraticCurveTo(cpx, cpy, x, y, mu)
    	if self._lastPoint then
    		local points = quadraticCurve(self._lastPoint[1], self._lastPoint[2], cpx, cpy, x, y, mu)
    		for i = 1, #points, 2 do
    			self:lineTo(points[i],points[i+1])
    		end
    	end
    	self._lastPoint = { x, y }
    	return self
    end
     
    function Shape:bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y, mu)
    	if self._lastPoint then
    		local inc = mu or 0.1 -- need a better default
    		for i = 0,1,inc do  
    			local p = bezier4(
    				{ x=self._lastPoint[1], y=self._lastPoint[2] },
    				{ x=cp1x, y=cp1y },
    				{ x=cp2x, y=cp2y },
    				{ x=x, y=y },
    			i)
    			self:lineTo(p.x,p.y)
    		end
    	end
    	self._lastPoint = { x, y }
    	return self
    end
    There are quite a few changes here so I've attached a copy of my current GiderosCodingEasy.lua to this post.

    When I first saw that you were recording all of the shape points I was a little dubious because if the potential memory issue for complex shape drawing. The fact that the existing implementation doesn't work makes me wonder whether you perhaps had a change of heart over this. I'd be grateful if you could let me know whether the above fixes fit with what you intended since, if not, it will impact how I implement these gradient fills I'm working on.

    best regards
    zip
    zip
    GiderosCodingEasy.lua.zip
    11K
  • Unfortunately yes, kinect is gone :-((
    Well back to everyday life, will try to get on this one next week ;)
  • bowerandybowerandy Guru
    edited December 2012
    @ar2rsawseen, here's another couple of minor fixes. You aren't currently passing the parameters to Sound:play() on to the overridden method. Around line 1092:
    function Sound:play(startTime, loops)
    	local channel = self:_play(startTime, loops)
    	if channel ~= nil then
    		channel.isPlaying = true
    Also, Sound:loop() should return the channel:
    function Sound:loop()
    	return self:play(0, math.huge)
    end
    best regards
  • ar2rsawseenar2rsawseen Maintainer
    edited December 2012
    Updated the repo, fixes applied:
    • skew transform fix by @moopf
    • getters for skew by @moopf
    • Shape internal points by @bowerandy
    • Shape drawpoly fix by @bowerandy (now accepts both tabled values and list of values)
    • passing parameters to Sounds:play by @bowerandy
    • returning channel from Sounds:loop by @bowerandy
    • accept filenames with file extensions by @bowerandy
    • arg is nil by @bowerandy
    • Text shadow alpha by @Scouser and @OZApps
    • Anchorpoints for texts are incorrect by @bowerandy
    • Rounding positions (including anchorpoints) by @moopf
    • Setting text messes anchorpoints (although not for BMFonts, but same thing happened to TextFields) by @moopf
    Things that are still left todo:
    • postToInputQueue() by @bowerandy (Is it still persists after the latest Gideros Update?)
    • alignAxisToVect by @Mells
    • skew messes anchorpoints by @moopf
    • skew messes positions by @moopf
    • Changing font for TextField by @OZApps
    • Box2d fixes and additions
    If I missed anything let me know.

    And @bowerandy is postToInputQueue still needed after latest update to Gideros?
    And I've implemented everything for internal point storage for Shape, I was also in doubt of how it will turn out, mainly would used memory be justified for the enhancements it could provide, but figured if you manage to do gradient Shapes then it certainly will ;)
  • @Arthurs, if it helps, here is a simple text with shadow, that will work for creating text with a shadow and offers changing the font, etc.
    function textWithShadow(theText)
    	local _grp = Sprite.new()
     
    	_grp.textColor = 0xffffff
    	_grp.shadowColor = 0x000000
    	_grp.fontName = nil
    	_grp.fontSize = 12
     
    	local _text
    	local _shadow
    	local _font 
     
    	function createText()
    		_text = TextField.new(_font, theText)
    		_text:setTextColor(_grp.textColor)
     
    		_shadow = TextField.new(_font, theText)
    		_shadow:setTextColor(_grp.shadowColor)
     
    		_grp:addChild(_shadow)
    		_shadow:setPosition(1,1)
    		_grp:addChild(_text)	
    	end 
     
    	createText()
     
    	stage:addChild(_grp)
     
    	function _grp:setFont(fontName, fontSize)	
    		self.fontSize = fontSize
    		self.fontName = fontName
    		_font = TTFont.new(fontName, fontSize)
    		_text:removeFromParent()
    		_shadow:removeFromParent()
     
    		createText()
    	end 
     
    	function _grp:setShadowColor(theColor)
    		self.textColor = theColor
    		_shadow:setTextColor(theColor)
    	end 
     
    	function _grp:setTextColor(theColor)
    		self.shadowColor = theColor
    		_text:setTextColor(theColor)
    	end 
     
    	function _grp:setText(theText)
    		_text:setTextColor(theText)
    		_shadow:setTextColor(theText)
    	end 
     
    	return _grp
    end
    and to use this, it is as simple as
    t = textWithShadow("Hello")
    t:setPosition(10,100)
    t:setFont("arial.ttf",24) --> Ensure that this font exists in your project
    t:setTextColor(0xff0000)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • bowerandybowerandy Guru
    edited December 2012
    And @bowerandy is postToInputQueue still needed after latest update to Gideros?
    And I've implemented everything for internal point storage for Shape, I was also in doubt of how it will turn out, mainly would used memory be justified for the enhancements it could provide, but figured if you manage to do gradient Shapes then it certainly will ;)
    Hi @ar2rsawseen, the latest Gideros release fixes the bug where I demonstrated a use for a "postToInputQueue" feature so it isn't needed to get around that problem now. However, I still feel it is a useful facility but, if no one else has yet come across a need for such a thing, then it might be best to leave it out for the time being.

    best regards
  • @bowerandy sure, could you elaborate on other situations where postToInputQueue would be useful?
    Maybe there some new interesting approach or design pattern I'm not aware of.
  • MellsMells Guru
    edited December 2012
    Based on the latest Sound API update, I wanted a way to control the number of loops a sound is played.
    I would like to suggest the following to be reviewed/included to GiderosCodingEasy :
    function Sound:playWithLoopCount(startTime, nbLoops)
    	nbLoops = nbLoops or 1
    	local soundLength = self:getLength()
     
    	local channel = self:play(startTime, true) -- loop infinitely
     
    	-- set looping as false after (loops - 0.5) count
    	Timer.delayedCall((nbLoops - 0.5) * soundLength, function() channel:setLooping(false) end)
     
    	return channel
    end
    Originated from my post here and a bit of precious help from Sir @atilim :)
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • @Mells, awesome thanks, will add it once I review all other changes with Sounds API that needs to be made ;)
  • Hi guys, newbie in gideros but try this fantastic stuff (OOP addicted :-)
    Since the last update, i get an error in my code and think i do something wrong, which actually was valid till the last gideros releases: I have a box class which is mainly a shape.
    ..
    Box = Core.class( Shape )
    function Box:init( config )
    ..
    end

    I thougt that, inheriting from the shape class, function Shape.new() should be first called and then my Box:init function. So did my app behave before my gideros update.
    But the code now crashes because moveto fct. misses _allPoint var of the GiderosCodingEasy definition.

    What i ma i doing wrong ?
    Didi something changed on the object creation in the new gideros version ?
    Thanks in advance,
    yarnee

  • bowerandybowerandy Guru
    edited March 2013
    @yarnee, yes something changed in 2012.9.10 and to use GiderosCodingEasy you'll need an update (hint, hint @ar2rsawseen). Basically, it is no longer allowable to override .new() if a class is later subclassed. The solution is to override .__new() instead.

    I'm attaching my current version of GiderosCodingEasy. There are some other changes in there as well; some are enhancements and others are bug fixes. @ar2rsawseen, would you care to review my changes and see which ones you'd like to include in the GitHub repo?

    best regards
    zip
    zip
    GiderosCodingEasy.lua.zip
    11K
    +1 -1 (+2 / -0 )Share on Facebook
  • @bowerandy, thanks a lot, i ll try it tonight and hope it works. :)>-
Sign In or Register to comment.