Comments (3)
Try renderTexture->getSprite()->getContentSize()
.
It is a little strange that RenderTexture content isn't set at creation, but if that were to be implemented, it may impact the positioning of the internal sprite, since it's a child of the RenderTexture. If the content size of the RenderTexture were to be set, then the position and anchor point of the internal sprite would need to be modified in order for it to be correct (and not break existing usage).
from axmol.
@rh101 Yes, I found that very strange and I step in the code to try to figure out what was the problem but defiantly it is not working. I could find a place where the value was set.
Doing this: renderTexture->getSprite()->getContentSize()
Will work but it is not intuitive and it doesn't fallow the rest the API pattern. I think this issue is not a high priority issue but it would be nice to have a clean interface. It's not intuitive to do this to get the size.
What do you think?
from axmol.
Will work but it is not intuitive and it doesn't fallow the rest the API pattern. I think this issue is not a high priority issue but it would be nice to have a clean interface. It's not intuitive to do this to get the size.
What do you think?
This is possible, but as I mentioned earlier, the internal sprite would need to be adjusted to ensure it is still drawn correctly.
So, in this method:
bool RenderTexture::initWithWidthAndHeight(int w,
int h,
backend::PixelFormat format,
PixelFormat depthStencilFormat,
bool sharedRenderTarget)
{
AXASSERT(format == backend::PixelFormat::RGBA8 || format == PixelFormat::RGB8 || format == PixelFormat::RGBA4, "only RGB and RGBA formats are valid for a render texture");
bool ret = false;
do
{
_fullRect = _rtTextureRect = Rect(0, 0, w, h);
w = (int)(w * AX_CONTENT_SCALE_FACTOR());
h = (int)(h * AX_CONTENT_SCALE_FACTOR());
_fullviewPort = Rect(0, 0, w, h);
setContentSize(Vec2(w, h)); // <<< set content size here
...
setSprite(Sprite::createWithTexture(_texture2D));
// !!!! Ensure sprite is displayed at correct coordinates anchoring bottom left.
_sprite->setAnchorPoint(Vec2::ZERO); // <<< ADDED
_sprite->setPosition(Vec2::ZERO); // <<< ADDED
...
}
Also, we can anchor the sprite to middle if that is preferred:
_sprite->setAnchorPoint(Vec2::ANCHOR_MIDDLE); // <<< ADDED
_sprite->setPosition(_contentSize / 2); // <<< ADDED
RenderTexture::getContentSize()
will then return the correct size.
@halx99 Is it reasonable to set the RenderTexture content size and make the above changes to the internal sprite so it is drawn correctly? If so, which is the preferred anchor point of the sprite, 0,0
or middle of render texture?
from axmol.
Related Issues (20)
- ax::ui::WebView cannot display local image HOT 5
- Bug in FreeType lib for certain fonts HOT 1
- macOS Edit wrong alignment
- FastRNG seems to have problematic implementation HOT 30
- Cannot Capture properly take a screen capture of ax::ui::ImageView HOT 4
- Two rapidjson with different version cause unexpected crash problem on apple family platforms HOT 15
- MediaPlayer Video not correctly rendered for Android 11 and older devices
- [ImGui] Invalid texture data drawn on modal popups HOT 1
- ArchLinux setup dependencies always fail
- VolatileTextureMgr::addImage memory leak HOT 1
- HttpClient释放response指针异常
- FontFreeType performance issues on Android HOT 2
- UITest.json source HOT 3
- Node:getChildren()性能问题 HOT 6
- Unknow function "setTargetFlags" & "ax::RenderTargetFlag" in Live2D extensions
- Font Issue with Emojis & Emoticons HOT 2
- TextureCache::addImage should be return when textures found.
- checkReallySupportsASTC does not work on ios device HOT 6
- Can't add package to XCode project HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axmol.