Giter Club home page Giter Club logo

rapanui's Introduction

--[[
--
--   _____                   _   _       _
--  |  __ \                 | \ | |     (_)
--  | |__) |__ _ _ __   __ _|  \| |_   _ _
--  |  _  // _` | '_ \ / _` | . ` | | | | |
--  | | \ \ (_| | |_) | (_| | |\  | |_| | |
--  |_|  \_\__,_| .__/ \__,_|_| \_|\__,_|_|
--              | |
--              |_|
--]]

RapaNui

by Ymobe ltd  (http://ymobe.co.uk)

LICENSE:

 RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0.
 CPAL is an Open Source Initiative approved
 license based on the Mozilla Public License, with the added requirement that you attribute
 Moai (http://getmoai.com/) and RapaNui in the credits of your program.

How to use RapaNui in your project:

1) Copy rapanui-sdk under your project dir
2) Copy config.lua from rapanui directory under your project
3) Add a require "config" into your main.lua
4) Add a require "rapanui-sdk.rapanui" into your main.lua

Now your main.lua should look something like this
require "config"
require "rapanui-sdk.rapanui"



How to test RapaNui in Moai distribution for Mac iOS:

1) under your moai dir find the dir "samples" create a new dir "RapaNui"
2) copy all the file of RapaNui (including sub subdirectories) in the new [YOUR_MOAI_DIR]/samples/RapaNui

in Moai's xcode ios SampleMoai project:

1) find the file named "moai-target" (should be under Resources -> build -> moai-target)
2) change the content to "../../samples/RapaNui"

now run the project



How to test RapaNui in Moai distribution for Windows:

1)download or clone RapaNui as is.

2)Find these files in the Moai distribution:
- moai.exe from Moai's bin folder
- config.lua from Moai's samples\config folder 

3)Now create .bat file in the RapaNui root directory.
Use the paths of those files and set the lua file to run.

Example .bat file (in this example Moai distribution is under C:\moai-sdk directory):

"C:\moai-sdk\bin\win32\moai.exe"
"C:\moai-sdk\samples\config\config.lua" 
"main.lua"

4)Now run the .bat file you've just created.



To change the demo of RapaNui

1) find and edit the main.lua under [YOUR_MOAI_DIR]/samples/RapaNui/main.lua
2) comment current sample with "--"
3) uncomment the sample you want to test.
4) run the project


enjoy,
The RapaNui team

rapanui's People

Contributors

cosmez avatar eljeko avatar galsas avatar mattiafortunati avatar odie avatar sporksmith avatar sylph avatar vertti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rapanui's Issues

Scaling problem

When you set a different scale than size (in RNScreen:initWith method), after, if you try to access to any Prop for example with a touch event , this fail.

This is solved adding "local x , y = RNFactory.screen.layer:wndToWorld(x, y)" in line 308 of RNInputManager.lua -> method onEvent.

Example:

function onEvent(eventType, idx, x, y, tapCount)

local screen = RNFactory.getCurrentScreen()

local x , y = RNFactory.screen.layer:wndToWorld(x, y)

local currenTarget = screen:getRNObjectWithHighestLevelOn(x, y);

local event = RNEvent:new()

event:initWithEventType(eventType)

event.x = x

event.y = y

...

Allowing an universal touch listener?

Wouldn't it be convenient to also handle all touch event in a single touch handler like in many other sdk as an option. Global universal touch listener is already in, but it'd be convenient for objects to be able to do this too. This way users doesn't have to register four different touch events, further cluttering the code. The user can separate the phases themselves in their touchHandler.

I'm aware that RNObject set a listener on the onTouchCallBackFunction var already, but it doesn't seem to be called.

Camera, MOAICamera support

RapaNui needs support to Moai's camera.

We need to check MOAICamera and how to implement it in RapaNui.

Feature request: handle transitions with groups

Actually we've modifyed RNTransitions to do something like this with groups and transitions:

for i = 1,myGroup.numChildren do

            local PosY = myGroup.displayObjects&[i].y + 1500;

            transition:run(myGroup.displayObjects[i], { type = "move", delay, time = 3500, alpha = 0, y = PosY})

    end

end

Only a tip if you would like to add transitions to groups. Thank you!

MOAI V1.0 MOAIEnvironment.getScreenSize() deprecated

In MOAI V1.0 the MOAIEnvironment.getScreenSize() was changed to MOAIEnvironment.screenWidth, MOAIEnvironment.screenHeight.

To reflect the changes, RNFactory.lua should be changed to

Line 47: local screenX, screenY = MOAIEnvironment.screenWidth, MOAIEnvironment.screenHeight
Line 49: if screenX ~= nil then --if physical screen

RNPhysics line change 'request'

in RNPhysics, change line 189 to

fixture = body:addCircle(0, 0, tempFixture.radius)

This allows you to set the radius by

RNPhysics.createBodyFromImage(image, {radius=10})

I think this was the intended function as that is all that has to be changed. I could probably pushed this to you, but I don't understand git as of yet too well.

Andrew

RNSpriteButton

Would love to see a button widget built into the framework. Some other frameworks such as cocos2d have pretty handy ones with their menu abstraction. Main thing needed is a selected and unselected state based on touch.

Removing a jope joint cause crash

With the following error:
.\rapanui-sdk/RNJoint.lua:585: attempt to index field 'joint' (a nil value)

Note: this does not happen with Revolute joints though it may happen with others but I have not tested that.

Reusing texture on multiple scenes lead to them being loaded multiple times.

Right now I'm reusing a texturepacker asset for main menu and credit scenes background. It currently keeps reloading the assets, as i switch back and forth between main menu scene and credit scene. The idea is to hopefully use a single texturepacker file for all the menu screens, and just remove it when i enter a game/exit menu.

I've fixed it with getAlreadyAllocated, but shouldn't this just be automatic?

    if not RNGraphicsManager:getAlreadyAllocated(scene.assets.atlasPath) then
        RNFactory.createAtlasFromTexturePacker(scene.assets.atlasPath, scene.assets.atlasLua)
    end

So I'm suggesting to adjust createAtlasFromTexturePacker so that it is more like

if not RNGraphicsManager:getAlreadyAllocated(image) then
        RNGraphicsManager:allocateTexturePackerAtlas(image, file)
end

PANIC: unprotected error in call to Lua API (RNFactory.lua)

In Moai SDK Version 1.0 Revision 3 I get this error:

PANIC: unprotected error in call to Lua API (./rapanui-sdk/RNFactory.lua:47: attempt to call field 'getScreenSize' (a nil value))

Workaround: change

local screenX, screenY = MOAIEnvironment.getScreenSize()

To

local screenX = MOAIEnvironment.screenWidth
local screenY = MOAIEnvironment.screenHeight

Editing vector shape colour after creation.

I do not understand the use of the colon, but here is the function (without the colon):

local square = RNFactory.createRect(0,0,50,50)
local circle = RNFactory.createCircle(200, 50, 25)
square.shape = "rect" -- put in RNObject when object is first made (or some other way)
circle.shape = "circle"

setColour = function(self,r,g,b)
    local function onDraw()
        MOAIGfxDevice.setPenColor(r * 0.00392, g * 0.00392, b * 0.00392, 1)--self.alpha)
        if self.shape == "rect" then
            MOAIDraw.fillRect(0,0,self.originalWidth,self.originalHeight)
        else 
            MOAIDraw.fillCircle(0, 0, self.originalWidth*.5, 32)
        end
    end
    self.gfxQuad:setDrawCallback(onDraw)
end

setColour(square, 255, 0 ,0)
setColour(circle, 0, 255 ,0)

addEventListener on an object does not call function.

Using RNListeners:
RNListeners:addEventListener( "touch", func )
does work.

The function I am using:

function func()
    print("touched")
end

image = RNFactory.createImage("image.png")
image:addEventListener( "touch", func ) -- RNListeners:addEventListener( "touch", func )

Translating a group before inserting children into it has no effect

Consider the following code sample - I would've expected rect to render at (100, 100) but it is instead left at (0, 0) (only changing g's position after inserting rect has the desired effect).

local g = RNGroup:new()
g.x, g.y = g.x + 100, g.y + 100
local rect = RNFactory.createRect(0, 0, 25, 25)
g:insert(rect)
--g.x, g.y = g.x + 100, g.y + 100

print(g.x, g.y)

Re-Use Textures / Texture-manager

I've already posted this on the Moai-Forum:
It would be great if RNFactory would accept already created images/animations to save memory.

Maybe a Texture-Manager would be the best solution, avoiding multiple instances of the same texture-file and avoiding unnecessary texture swichting by sorting draw-calls (afaik texture switching makes things slow)

Fix needed to font automatic cache.

Font is caching in a strange way at the moment because font:load it's just for setting a font path, not to properly load a font. If we use the same charcodes and the same font, the cache is working, else we should use like "preloadGlyphs".

We need deeper researching on this.

:D

Groups in lists causes crash fix

There is an issue in lists where if you add groups the app crashes on destruction. The fix is to properly handle the remove() call ot the RNGroup object initiated by the list on removal

Following up on this issue. It looks like when a RNListView is being
removed it calls v.object:remove on all its elements. This does not
work for RNGroup because it has the function:

function RNGroup:remove(value)

self:removeChild(value:getIDInGroup())

end

The fix is to remove each of the groups children. See below. (might
be missing some cleanup here but it looks like it works)

-- SS. added to properly remove groups from RNListView

function RNGroup:remove()

print("RNGroup:remove(value)")

print("num children", self.numChildren)

childrenCount = self.numChildren

for i = 1, childrenCount do

print("remove a child", i)

self.displayObjects[1]:remove()

end

end

explicit calls to collectgarbage causing performance hit

Remove object is explicitly calling the lua collectgarbage calls is causing slowdowns when changing scenes. This is especially true with scene of many objects such as lists of 300 items. If you remove these calls an call this function less frequently, it massively increases app performance. I am not sure but lua may be doing the memory management anyway so these calls should not be needed at all.

Handling black bar when config.stretch is set to true

I think it'll be a great feature to add an option that would allow us to still draw on the inadvertent black bars on the side, when config.stretch is set to true?

Manually scaling every object in the game code makes for a rather messy code, unless there's another option that I missed?

Thanks ^^

RNBody:getMass is missing?

Hello.

I was looking at the source.
RNBody:getMass is missing?


function RNBody:getMass()
return self.body:getInertia()

end

Runtime events feature

It would be great to have Runtime events for backbutton for android or accelerometer, hardwarekeys etc..

Support MOAITextBox: spool

It would be nice to have the Moai TextBox spool functions directly available from RNTextBox. That would include spool, more, next page, reveal, reveal all, and busy.

RapaNui should be multi Layer

At the moment RapaNui works in a single layer.
It should handle more than one layer instead.

We need like:
RNFactory:addLayer()
RNFactory:removeLayer()
and something like a new param in creations:
RNFactory.createImage("image",{layer=layer})--param should be optional to keep compatibility with old projects not using multilayering. Image default behaviour won't change, it will be put on default layer RNFactory.screen

EDIT 1:

niom suggestions:

RNLayer

this class should handle layer creation, storing and removing layers
we should have way to create a layer with and without MOAIPartition -- createLayer -- createLayerWithPartition

RN parts affected by multilayer

  1. Initializing screen

When initializing screen we should create the main layer as before
Main layer should be stored to RNLayer (new RN class) these could be done by using the new RNLayer.createLayerWithPartition()

  1. Creating a new RNObject from image

we should be able to pass the layer to the image creation and if the layer is missing we should use the main layer
new MOAIProp is added to the layer in RNObject:initWithImage2, so we should be able to pass the layer in that function. Fortunately initWithImage2 takes only one parameter, the image, in so this should be easy.
To support backwards compatibility we should use a new function for createImage, ie. createFromImage(image,layer,parameters) and make the createImage to use createFromImage with main layer

  1. Removing RNObject from layer

RNScreen:removeRNObject(object) should be able to take the layer as a parameter so the removed object would be removed from that layer.
in case the layer parameter is not passed then we should remove the object from all of the layers, by using the RNLayer class

EDIT 2:

  1. Issue #91 should be considered during the implementation of this feature.

  2. Also, a sample folder labeled "multilayer" with a couple of samples on how to use multilayer feature should be good.

bug in setDebugDraw

I run the sample rapanui-samples/physics/rn-physics-lists and is report an error

I look into the source

--we need the layer from RNScene received
--keep it in mind for future changes
function setDebugDraw(screen)

local layerfordebug = screen.layer
len = table.getn(screen.sprites)
for i = 0, len, 1 do
    screen.sprites[i].visible = false
end
layerfordebug:setBox2DWorld(world)

end

i should start from 1

Text styles

RNTexts should support MOAI Styles.
And Spool.
And HighLight.

newShape using MOAIDraw

Pull requests are too complicated for me.

Can be called using:
local circle = R.Factory.newCircle(0,0,100)
local square = R.Factory.newRect(0,0,100,100)

RNFactory:
http://pastebin.com/zLJK0Le7

RNObject:
http://pastebin.com/jkhXJqmp

Forgive me for using a table to store RN and not using module see..all. (That is why functions are called "R.Object.new()" for example.

I am sure the two functions could be merged.

MOAIImageTexture does not seem to be supported

With RapaNui, I'm not able to dynamically update a MOAIImageTexture object already bound to GPU memory from an input event handler. I display the texture with RNFactory.createImageFromMoaiImage () function, which accepts a MOAIImage object. MOAIImageTexture inherits from MOAIImage, so I expect that createImageFromMoaiImage () should work fine passed in a subclass of what it expects. This may be a bug somewhere, as MOAIImageTexture is something that has recently been added to MOAI. Thanks!

Code to reproduce:

require("rapanui-sdk/rapanui")

SCREEN_WIDTH = RNFactory.screen.width
SCREEN_HEIGHT = RNFactory.screen.height

print ( "hello" )
local background = RNFactory.createImage ( "images/background-blue.png" )
background:sendToBottom ()
print ( "displayed background" )

texture = MOAIImageTexture.new ()
texture:load ( "C:/dev/sdks/moai-sdk/samples/hello-moai/moai.png", MOAIImage.TRUECOLOR + MOAIImage.PREMULTIPLY_ALPHA )
print ( "loaded texture" )

-- demonstrate that we can modify the texture before rendering it
-- this draws a red line 50 pixels long diagonally from the top left
for i = 0,50 do
    texture:setRGBA ( i, i, 1, 0, 0, 1 )
end

image = RNFactory.createImageFromMoaiImage ( texture )
image.x = SCREEN_WIDTH/2
image.y = SCREEN_HEIGHT/2
print ( "displayed image from texture" )

function onTouchEvent ( event )
    if event.phase == "began" then
        print ( "touch begin" )

        -- this should draw a white line 128 pixels long diagonally from the top left
        for i = 0,127 do
            texture:setRGBA ( i, i, 1, 1, 1, 1 )
        end 
        texture:invalidate ()
    elseif event.phase == "ended" then
        print ( "touch end" )

        -- this should draw a blue line 128 pixels long diagonally from the top left
        for i = 0,127 do
            texture:setRGBA ( i, i, 0, 0, 1, 1 )
        end
        texture:invalidate ()
    end
end

local listenerId = RNListeners:addEventListener("touch", onTouchEvent)

listview jumps when scrolling up and down past maxy or miny

When you scroll past the max or min y in the RNlistview the list jumps.

From what I can tell the event.y value returns and jumps 100-200 points when you change direction of the scroll.

Figured out this is caused by the hard coding of 100 in the line.

                if SELF.deltay > 0 and SELF.y < SELF.options.maxY + 100 or SELF.deltay <= 0 and SELF.y > SELF.options.minY - 100 then
                    if self.beganDelta ~= nil then
                        self.y = event.y - self.beganDelta
                    end
                end

Director + touch event

case :

  • a director switch 2 scenes with clic on buttons (one button per scene)
  • buttons have listeners like btn:setOnTouchDown(handler)
  • the listener doesn't work on the 2nd scene

I'm quite new to rapanui so i'm just guessing where the problem is :

  • director creates new scene in RNScreen, self.sprites grows up
  • then director destroy the first view, RNScreen:removeRNObject is called and self.sprites reduces HOWEVER rnObjectId isn't change
  • when RNScreen:getRNObjectWithHighestLevelOn is called, the button is never find because rnObjectId > ||self.sprites||

possible solution : add self.sprites[k]:getProp().rnObjectId = k - 1 in RNScreen, at line 93. I didn't test potential side effects

Screen isn't being auto scaled

I thought if the config is set properly, then an image following the first 2 values of config.sizes would get upscaled to the last 2 values. I have config.stretch set to true and config.graphics Design set to 960 640. I tested it with an image of 960 640 size.

My config is

config = {}
config.sizes = {}

config.sizes["iPadDev"] = { 768, 1024, 384, 512 } -- shrunk for easier viewing
config.sizes["iPad"] = { 768, 1024, 768, 1024 } -- 1:1 pixel iPad
config.sizes["iPhone3G"] = { 320, 480, 320, 480 }
config.sizes["iPhone4Full"] = { 640, 960, 640, 960 }
config.sizes["iPhone3G_500_750"] = { 320, 480, 500, 750 } -- 3G screen ratio upscaled to 500x750
config.sizes["AcerLiquidMetal"] = { 480, 800, 480, 800 }
config.sizes["test"] = { 700, 1024, 700, 1024 }
config.sizes["test2"] = { 200, 400, 200, 400 }

config.landscape = true
config.device = "iPhone3G_500_750"

config.stretch = true
config.graphicsDesign = { w = 960, h = 640 }

return config

The result of
print ("bg size:", mainMenuBG:getOriginalWidth(), mainMenuBG:getOriginalHeight())
print ("screen size", RNFactory.screen.width, RNFactory.screen.height)
are
bg size: 960 640
screen size 480 320

No way to set timestep for Box2D

Unless I am missing something you cannot set the timestep for Box2D. You can certainly set the iterations but not the timestep.

Creating Shapes offset by center leads to odd code

I spent a hour trying to figure out why this:
nextLink = RNFactory.createRect(link.x, link.y, width, height, { rgb = { 255, 0, 0 } })

Is not the same as:
nextLink = RNFactory.createRect(0, 0, width, height, { rgb = { 255, 0, 0 } })
nextLink.x = link.x
nextLink.y = link.y

It would be better to either override the equals to do the same (not the best way to do it) or have objects created with the correct x, y and have the user fix the difference. otherwise you get code that simply does not make sense.

Transition references

all the transition demos are having problems when they end..

for example

action:setListener(MOAIAction.EVENT_STOP, function() params.onComplete(target) end)

causes the following error

PANIC: unprotected error in call to Lua API (./RNTransition.lua:134: attempt to call method 'setListener' (a nil value))

Groups inside groups

Group = RNGroup:new()
Group2 = RNGroup:new()
Group:insert(Group2)

Will print:
PANIC: unprotected error in call to Lua API (...and Settings\Andrew\Desktop\moai work\RN\RNGroup.lua:123: attempt to call method 'setParentGroup' (a table value))

RNTimer sample

How can i use a timer that repeats only one time? It would be easier for some turnbase games...

Physics inside of groups causes -x offset when modifying position

If an image is a physics object is added to a group, hen the objects position is modified during the frame update then it causes an -x offset of about 2.03.

To reproduce. Create a physics image, set a position near the middle top of the screen, add it to a group. Then in the frameupdate handler do something like myObject.y = myObject.y + 1

The object will fall to the left slowly (and down obviously because of the physics). It seems very weird as it doesn't happen unless it is in a group and even odder that it happens even if you only modify the y position (Though it still messes up if you modify the x position only.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.