This is my first post on the forum after messing around with Defold for the first time after 6 years with Gideros.
First impressions? Great! But… a lot different. I spent the last 3 days following tutorials and trying to understand how the new engine works. I think that I’ve got a rough idea on how things work (at least the basic basics), my objective is to port one of my unfinished projects from Gideros to Defold.
Obviously I can’t just copy and paste all the code from one engine to another and I’m starting slowly by implementing small and simple objects that will be included in the final game. I hope to learn and work on the project at the same time.
Now, coming to the topic’s title. The objective is to create something like that:
Nothing fancy, just some shapes rotating clockwise and counterclockwise. The way I did in Gideros was to create a class GraphicRays and then generate N shapes with some simple math (not the most efficient nor best way, but it works nicely). Then a timer would take care of the rotation.
for i=1, self.rays*2 do if(i%2==0)then local current1Degrees=math.rad(i*self.degreesPerRay/2); local current2Degrees=math.rad((i+1)*self.degreesPerRay/2); local val1X=self.radius*math.cos(current1Degrees) local val1Y=self.radius*math.sin(current1Degrees) local val2X=self.radius*math.cos(current2Degrees) local val2Y=self.radius*math.sin(current2Degrees) local tempShape=Shape.new() tempShape:setFillStyle(Shape.SOLID, self.color) tempShape:beginPath() tempShape:moveTo(0,0) tempShape:lineTo(val1X, val1Y) tempShape:lineTo(val2X, val2Y) tempShape:closePath() tempShape:endPath() self.shapes[i/2]=tempShape self.raysContainer:addChild(self.shapes[i/2]) end end
In Defold I attempted the following “implementations” (from the “worst” to the ideally best):
- Use a pre-rendered image of the rays and just rotate it in a script. (Works but it’s not memory efficient and the number of rays can’t be changed)
- Use a pre-rendered image of one slice of the rays, use a factory to copy the sprite to multiple angles and then rotate all the sprites (kind of works, more efficient but the width of the rays can’t be changed without stretching the single ray)
- Use generated ray as I did in Gideros (couldn’t find a way to draw the shapes dynamically, the only solution I found is to message the renderer with
draw_linebut people said that it should be used for debugging only: How to draw rectangles, circles)
What I’m trying to achieve:
- The number of rays should be decided when the object is initialized.
- The rays rotation speed should be changed on the fly (easy, done with messages).
- The rays color should be editable (easy? Rotate the hue of the sprites).
What approach would you choose to solve this “problem”? I’m still in the Gideros-way of thinking and I really want to open my mind the new possibilities Defold offers.